Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Can't find phantomjs or execute phantomjs #142

Closed
rluisr opened this issue Nov 24, 2016 · 6 comments
Closed

Can't find phantomjs or execute phantomjs #142

rluisr opened this issue Nov 24, 2016 · 6 comments

Comments

@rluisr
Copy link

rluisr commented Nov 24, 2016

Overview

My PHP Code says error occurred.

PHP Fatal error:  Uncaught JonnyW\PhantomJs\Exception\ProcedureFailedException: Error when executing PhantomJs procedure - File does not exist or is not executable: bin/phantomjs in /mnt/smbSSD_128GB/WebStorm/test-phantomjs/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Procedure/Procedure.php:138
Stack trace:
#0 /mnt/smbSSD_128GB/WebStorm/test-phantomjs/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Procedure/ProcedureValidator.php(84): JonnyW\PhantomJs\Procedure\Procedure->run(Object(JonnyW\PhantomJs\Procedure\Input), Object(JonnyW\PhantomJs\Procedure\Output))
#1 /mnt/smbSSD_128GB/WebStorm/test-phantomjs/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Procedure/ProcedureValidator.php(61): JonnyW\PhantomJs\Procedure\ProcedureValidator->validateSyntax('\n\n/**\n * Set up...')
#2 /mnt/smbSSD_128GB/WebStorm/test-phantomjs/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Procedure/ProcedureCompiler.php(107): JonnyW\PhantomJs\Procedure\ProcedureValidator->validate('\n\n/**\n * Set up...')
#3 /mnt/smbSSD_128GB/WebStorm/test-ph in /mnt/smbSSD_128GB/WebStorm/test-phantomjs/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Procedure/Procedure.php on line 138

Code

<?php
require_once 'vendor/autoload.php';

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();

$request = $client->getMessageFactory()->createRequest('http://jonnyw.me', 'GET');
$response = $client->getMessageFactory()->createResponse();

$client->send($request, $response);

if ($response->getStatus() === 200) {
    echo $response->getContent();
}

Tree

.
├── bin
│   └── phantomjs [chmod 777]
├── composer.json
├── composer.lock
├── test.php
└── vendor
    ├── autoload.php
    ├── composer
    ├── jakoch
    ├── jonnyw
    ├── symfony
    └── twig

Version

PHP 7.1.0RC6 (cli) (built: Nov 9 2016 09:51:59) ( NTS )
php-phantomjs latest

Why this php code doesn't work?

@jonnnnyw
Copy link
Owner

jonnnnyw commented Dec 5, 2016

Try setting an absolute path to your PhantomJS executable.

$client = Client::getInstance();
$client->getEngine()->setPath('/path/to/phantomjs');

If that doesn't work then try installing PhantomJS manually - http://phantomjs.org/download.html

@rluisr
Copy link
Author

rluisr commented Dec 30, 2016

@jonnnnyw Sorry for the late reply.
Thanks reply and solve this problem.

@jakoch
Copy link
Contributor

jakoch commented Jan 31, 2017

  1. update to "jakoch/phantomjs-installer": "2.1.1-p08", see patch updating jakoch/phantomjs-installer to 2.1.1-p08 #149
  2. use helper class PhantomBinary - https://github.com/jakoch/phantomjs-installer#phantombinary,
    see patch Removes the dependency on the /bin hardcoded path. #155

@jonnnnyw
Copy link
Owner

Have merged this in. Just running tests and will be released in v6.0.

@yuseferi
Copy link

yuseferi commented May 2, 2017

The following codes will help you to fix the problem:

  • on windows:
    $client->getEngine()->setPath(dirname(__FILE__).'/bin/phantomjs.exe');

  • on mac and Linux
    $client->getEngine()->setPath(dirname(__FILE__).'/bin/phantomjs');

these helped me to fix the issue.

@salvatorecapolupo
Copy link

salvatorecapolupo commented Jan 2, 2021

if you are using Composer, you can fix this error using this code line:

$client->getEngine()->setPath('vendor/bin/phantomjs');

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants