我正在尝试在CentOS 7和Windows 8下将php-phantomjs与 Laravel 5一起使用。
我按照PHP Phantom 安装(安装成功)中的说明进行操作,之后在尝试执行基本用法代码时收到此错误:
执行 PhantomJs 过程“默认”时出错 - 文件不存在或不可执行:bin/phantomjs(查看:PATH_TO_PROJECT\resources\views\welcome.blade.php)
基本使用代码
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
/**
* @see JonnyW\PhantomJs\Message\Request
**/
$request = $client->getMessageFactory()->createRequest('http://google.com', 'GET');
/**
* @see JonnyW\PhantomJs\Message\Response
**/
$response = $client->getMessageFactory()->createResponse();
// Send the request
$client->send($request, $response);
if($response->getStatus() === 200) {
// Dump the requested page content
echo $response->getContent();
}
我用谷歌搜索了很多,找到并尝试了几种解决方案,但没有成功。在 Stackoverflow 上,我发现了一个问题有人在 ubuntu 环境中成功使用了 jonnyw 的“php phantomjs”和 laravel 吗?. 我可以在最后一条评论中看到这个人解决了这个问题:
$client->setBinDir('absolute_path/bin');
$client->setPhantomJs('phantomjs.exe');
我也试过了,它返回另一个错误:
文件不存在或不可执行:phantomjs.exe(查看:PATH_TO_PROJECT\resources\views\welcome.blade.php)
但是当我尝试时:
echo file_exists('absolute_path/bin/phantomjs.exe');
它返回 1,这意味着 PHP 可以找到带有absolute_path
.
我不知道我做错了什么。任何已经在 laravel 中成功使用“php phantomjs”的人可以帮助我吗?
注意:有问题的代码是 Windows 版本代码,但我在两个操作系统中都收到相同的错误。
更新 1
更改absolute_path
为relative path
它似乎现在知道phantomjs.exe
了,但是钢提出了同样的错误phantomloader
:
文件不存在或不可执行:../bin/phantomloader(查看:PATH_TO_PROJECT\resources\views\welcome.blade.php)
尝试了这个解决方案,但同样的错误:
$client->setPhantomLoader('../bin/phantomloader');