EzDevInfo.com

php-phantomjs

Execute PhantomJS commands through PHP

php-phantomjs with Laravel (File does not exist or is not executable: bin/phantomjs)

I'm trying to use php-phantomjs with Laravel 5 under CentOS 7 and Windows 8.

I followed the instructions at PHP Phantom installation (installation done with success), after that I received this error while trying to execute the Basic Usage code:

Error when executing PhantomJs procedure "default" - File does not exist or is not executable: bin/phantomjs (View: PATH_TO_PROJECT\resources\views\welcome.blade.php)


Basic usage code

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();
}

I Googled a lot, finding and trying several solutions, but without success. Here on Stackoverflow, I found one question Anyone successfully used jonnyw's “php phantomjs” with laravel, in a ubuntu envirement?. I can see in the last comment that the guy solved the problem with:

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

I triyed that also and it's return another error :

File does not exist or is not executable: phantomjs.exe (View: PATH_TO_PROJECT\resources\views\welcome.blade.php)

But when I try:

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

It returns 1 which means PHP can find the file with absolute_path.


I don't know what I'm doing wrong. Anyone successfully used “php phantomjs” with laravel who can help me?

NOTE : The code included in question is a windows version code, but i receive the same error in the both OS.


UPDATE

After changing absolute_path to relative path it seem like it know phantomjs.exe now, but steel raise same error with phantomloader:

File does not exist or is not executable: ../bin/phantomloader (View: PATH_TO_PROJECT\resources\views\welcome.blade.php)

Tried this solution, but same error :

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

Source: (StackOverflow)