我正在尝试使用 php-phantomjs 在 CentOS 7 和 Windows 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_path
至 relative 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/