I am trying to use PHP PhantomJS to load a page, but I get the error
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
This only happens on one of my test domains, and not the other.
The code I am running on both domains is identical, but doesn't work on one of the two test beds. Both are running on the same machine, just using different virtual hosts, but only one is returning the error.
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();
}
I have tried setting the path to phantomjs
in the composer.json
file using
"config": {
"bin-dir": "/usr/local/bin"
}
but this doesn't seem to make any difference
When you run Composer to install your packages the PhantomJS-Installer script will fetch PhantomJS and install it into the /bin
folder of the project.
It will never land in /usr/local/bin
, except when you manually install or move it there.
You get the following error message: File does not exist or is not executable:
bin/phantomjs
.
Firstly, i would check, if the file is correctly fetched and installed into the bin
folder. (If the file is not installed into the bin folder of your project, then the installer script should give you an error during the Composer run.)
Secondly, i would check file permissions. Normally the installer takes care of that, but just take a look, if the executable flag +x
is set.