Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ProcedureFailedException #19

Closed
moe-m opened this issue Aug 4, 2014 · 14 comments
Closed

ProcedureFailedException #19

moe-m opened this issue Aug 4, 2014 · 14 comments

Comments

@moe-m
Copy link

moe-m commented Aug 4, 2014

Fatal error: Uncaught exception 'JonnyW\PhantomJs\Exception\ProcedureFailedException' with message 'Error when executing PhantomJs procedure "default" - File does not exist or is not executable: bin/phantomjs'

I followed the instructions and manually created my bin folder in the project root. phantomjs.exe, phantomloader, and phantomloader.bat were installed successfully. Not sure why this cannot execute. In your previous version I remember manually changing the location from phantomjs to phantomjs.exe in client.php to work with Wndows. Manually setting $client->setBinDir in examples/basic-request.php results in the same error.

@jonnnnyw
Copy link
Owner

jonnnnyw commented Aug 5, 2014

Hi, can you post a snippet of the code that you are using to make the request?

@moe-m
Copy link
Author

moe-m commented Aug 5, 2014

this is your examples/basic-request.php

require '../vendor/autoload.php';
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
$request = $client->getMessageFactory()->createRequest();
$response = $client->getMessageFactory()->createResponse();
$request->setMethod('GET');
$request->setUrl('http://google.com');
$client->send($request, $response);
var_dump($response);

@jonnnnyw
Copy link
Owner

jonnnnyw commented Aug 5, 2014

Can you run this and let me know what it outputs/throws:

    require '../vendor/autoload.php';

    use JonnyW\PhantomJs\Client;

    $client = Client::getInstance();

    var_dump($client->getCommand());

@moe-m
Copy link
Author

moe-m commented Aug 5, 2014

file structure: http://i.imgur.com/FCwgdPL.png
code:

<?php
//test.php
 require 'vendor/autoload.php';

    use JonnyW\PhantomJs\Client;

    $client = Client::getInstance();

    var_dump($client->getCommand());

Result:
http://i.imgur.com/NJuoR0D.png

Uncaught exception 'JonnyW\PhantomJs\Exception\InvalidExecutableException' with message 'File does not exist or is not executable: bin/phantomjs' in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\web-optimization\phantomjs4\src\vendor\jonnyw\php-phantomjs\src\JonnyW\PhantomJs\Client.php on line 383

@jonnnnyw
Copy link
Owner

jonnnnyw commented Aug 5, 2014

That means it can't find your phantomjs executable or it doesn't have permissions to execute it. It could be that you are executing the script from somewhere other than the directory above your bin dir, which is where it is looking for the phantomjs executable.

Make sure you're using v3.1+ and try the following:

    require 'vendor/autoload.php';

    use JonnyW\PhantomJs\Client;

    $client = Client::getInstance();
    $client->setBinDir('/absolute/path/to/your/bin/directory');

    var_dump($client->getCommand());

Make sure the path is absolute to your bin directory.

If that doesn't work then check that the user you are running your script as has permissions to execute the files in your bin folder.

@moe-m
Copy link
Author

moe-m commented Aug 6, 2014

Hey Jonnyw,

Some quick checks in php says that phantomjs.exe is writable. In your previous version I had to manually append .exe on the phantomjs location in client.php......maybe that's the trouble?

Code:

<?php
//test.php

$file = "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($file)){
    echo ("$file is executable");
    }else{
        echo ("$file 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');

    var_dump($client->getCommand());

Result:
image

@scratcher28
Copy link

@moe1507, the same I did.
appending .exe solves the issue.

@moe-m
Copy link
Author

moe-m commented Aug 6, 2014

@scratcher28 , Where do I append .exe. I haven't found it yet in the new version(3.1).

@jonnnnyw
Copy link
Owner

jonnnnyw commented Aug 6, 2014

You can do it a couple of ways. If you are running the script from the parent directory of your bin folder, just set the PhantomJS path as follows:

    require 'vendor/autoload.php';

    use JonnyW\PhantomJs\Client;

    $client = Client::getInstance();
    $client->setPhantomJs('bin/phantomjs.exe');

    var_dump($client->getCommand());

Or you can set the bin dir separately and then set the PhantomJS executable:

    require 'vendor/autoload.php';

    use JonnyW\PhantomJs\Client;

    $client = Client::getInstance();
    $client->setBinDir('/absolute/path/to/your/bin/dir');
    $client->setPhantomJs('phantomjs.exe');

    var_dump($client->getCommand());

The second option is probably recommended as it guarantees that the client can find your bin dir.

I will update the install documentation with this information. Ideally it would be nice to automatically set the extension based on the installed system. I will look into it.

@moe-m
Copy link
Author

moe-m commented Aug 7, 2014

tried the above....still not executable.

test.php

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

result:

image

@scratcher28
Copy link

public function getPhantomJs()
{
    return sprintf($this->phantomJs, $this->getBinDir());
}

when calling sprinf(): $this->phantomJs is empty...

...

private function validateExecutable($file)
{
    $file = str_replace("/", "\\", $file); // my fix

@jonnnnyw
Copy link
Owner

jonnnnyw commented Aug 8, 2014

That's odd that $this->phantomJs is empty when calling sprintf. I have tests for validating the setting of custom paths and they are passing. I will go back and look at the tests and see if they are valid.

I guess the root of your problem is down to the fact that you are using backslashes. Have you thought about using forward slashes so that your code is portable across across different environments? My understanding is that Windows supports forward slashes.

@perochak
Copy link

perochak commented Dec 6, 2016

Faced same issue.

Fixed it using following code

$client->getEngine()->setPath(dirname(FILE).'/bin/phantomjs.exe');

@yuseferi
Copy link

yuseferi commented May 2, 2017

This

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

fix the issue for me.

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

No branches or pull requests

5 participants