phplaravelcentoslaravel-5.1php-phantomjs

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 already 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 1

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');

Solution

  • Well, have a look at the video here: https://www.youtube.com/watch?v=unLTKz9Jqyw

    This guy explains all the stuff you might need. Hope that helps.

    EDIT:

    Try putting this code...

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