0

我正在尝试使用 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();
}

我尝试使用phantomjscomposer.json文件中设置路径

"config": {
  "bin-dir": "/usr/local/bin"
}

但这似乎没有任何区别

4

1 回答 1

0

当您运行 Composer 安装包时,PhantomJS-Installer 脚本将获取 PhantomJS 并将其安装到/bin项目的文件夹中。

它永远不会登陆/usr/local/bin,除非您手动安装或移动它。

您收到以下错误消息:File does not exist or is not executable: bin/phantomjs

首先,我会检查文件是否被正确提取并安装到bin文件夹中。(如果文件未安装到项目的 bin 文件夹中,则安装程序脚本应该在 Composer 运行期间给您一个错误。)

其次,我会检查文件权限。通常安装程序会处理这个问题,但只要看看是否+x设置了可执行标志。

于 2016-07-07T22:42:55.397 回答