我正在尝试使用 PHP PhantomJS 加载页面,但出现错误
Fatal error: Uncaught JonnyW\PhantomJs\Exception\ProcedureFailedException: Error when executing PhantomJs procedure - File does not exist or is not executable: bin/phantomjs in /Volumes/WWW ROOT/namechase/www/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Procedure/Procedure.php:138
Stack trace:
#0 /Volumes/WWW ROOT/namechase/www/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Client.php(162): JonnyW\PhantomJs\Procedure\Procedure->run(Object(JonnyW\PhantomJs\Http\Request), Object(JonnyW\PhantomJs\Http\Response))
#1 /Volumes/WWW ROOT/namechase/www/crawling.php(30): JonnyW\PhantomJs\Client->send(Object(JonnyW\PhantomJs\Http\Request), Object(JonnyW\PhantomJs\Http\Response))
#2 {main}
thrown in /Volumes/WWW ROOT/namechase/www/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Procedure/Procedure.php on line 138
这只发生在我的一个测试域上,而不是另一个。
我在两个域上运行的代码是相同的,但在两个测试台之一上不起作用。两者都在同一台机器上运行,只是使用不同的虚拟主机,但只有一个返回错误。
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
echo '<pre>';
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
$delay = 5; // 5 seconds
$request = $client->getMessageFactory()->createRequest('https://google.com', 'GET');
$request->setDelay($delay);
/**
* @see JonnyW\PhantomJs\Http\Response
**/
$response = $client->getMessageFactory()->createResponse();
// Send the request
$client->send($request, $response);
if($response->getStatus() === 200) {
// Dump the requested page content
echo $response->getContent();
}
我尝试使用phantomjs
在composer.json
文件中设置路径
"config": {
"bin-dir": "/usr/local/bin"
}
但这似乎没有任何区别