带有 Laravel 的 Php-phantomjs(文件不存在或不可执行 : bin/phantomjs)

标签 php laravel centos laravel-5.1 php-phantomjs

我正在尝试使用 php-phantomjs CentOS 7Windows 8 下使用 Laravel 5。

我按照 PHP Phantom installation 的说明进行操作(安装成功),之后我在尝试执行基本用法代码时收到此错误:

执行 PhantomJs 过程“默认”时出错 - 文件不存在或不可执行:bin/phantomjs( View :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 上,我发现了一个问题 Anyone successfully used jonnyw's “php phantomjs” with laravel, in a ubuntu envirement? 。我可以在最后一条评论中看到这个人解决了这个问题:

$client->setBinDir('absolute_path/bin');
$client->setPhantomJs('phantomjs.exe');

我也试过了,它返回了另一个错误:

文件不存在或不可执行:phantomjs.exe( View :PATH_TO_PROJECT\resources\views\welcome.blade.php)

但是当我尝试时:

echo file_exists('absolute_path/bin/phantomjs.exe');

它返回 1,这意味着 PHP 可以找到带有 absolute_path 的文件.


我不知道我做错了什么。任何人已经成功地将“php phantomjs”与 laravel 一起使用谁可以帮助我?

注意:问题中包含的代码是 Windows 版本代码,但我在两个操作系统中都收到相同的错误。


更新 1

更改后absolute_pathrelative path好像知道phantomjs.exe现在,但是钢铁用 phantomloader 引发了同样的错误:

文件不存在或不可执行:../bin/phantomloader( View :PATH_TO_PROJECT\resources\views\welcome.blade.php)

试过这个解决方案,但同样的错误:

$client->setPhantomLoader('../bin/phantomloader');

最佳答案

好吧,看看这里的视频: https://www.youtube.com/watch?v=unLTKz9Jqyw

此人解释了您可能需要的所有内容。希望对您有所帮助。

编辑:

尝试输入这段代码...

<?php
//test.php

$phantom_loc = "C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\web-optimization\phantomjs4\src\bin\phantomjs.exe";

$dir = "C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\web-optimization\phantomjs4\src\bin\\";

//Is dir executable
$dir_is_Writeable = @file_exists($dir . ".");

if ($dir_is_Writeable === true) {
    echo "$dir is writable";
} else {
    echo "$dir is not writable";
}

echo "<br><br>";
//is executable
if(is_executable($phantom_loc)) {
    echo ("$phantom_loc is executable");
} else {
    echo ("$phantom_loc is not executable");
}

echo "<br><br>";

//Jonnyw
require 'vendor/autoload.php';

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();
$client->setBinDir('C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\web-optimization\phantomjs4\src\bin\\');
$client->setPhantomJs('phantomjs.exe');

var_dump($client->getCommand());

关于带有 Laravel 的 Php-phantomjs(文件不存在或不可执行 : bin/phantomjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32015599/

相关文章:

mysql - 如何使用 `sql/mysql` 从公共(public)列下的 `groupby` 获取嵌套数组,而不使用 foreach 来构造数据?

python - 将 conda HDF4 链接到 conda GDAL(Anaconda Python)

php - pcntl_fork() 中超过 300 秒的最大执行时间

php - PHP 的 json_encode 中的西里尔字符

php - 使用 Docker 隔离 PHP 应用程序

php - 不确定我的映射在 Elasticsearch 中是否有效

javascript - 从数据库中排序选择框选项

python - 在 CentOS 与 python 2.6 上针对 information_schema 执行 "SELECT"语句时,psycopg2 挂起

php - 从php插入一个数组到mysql

php - 连接到多个数据库