Lander
Lander

Reputation: 3437

Error code 127 returned when using exec() to run PhantomJS

In my Vagrant environment (haven't tested on the server) I keep getting an error when trying to run PhantomJS using exec() from one of my website's controllers.

Here's the code I'm using to debug:

exec('/usr/local/node/node-default/bin/node --version', $output, $code);
var_dump($code);
exec('ls -la /usr/local/node/node-default/bin/phantomjs', $output, $code);
var_dump($code);
exec('/usr/local/node/node-default/bin/phantomjs --version', $output, $code);
var_dump($code);
exec('/usr/local/node/node-default/lib/node_modules/phantomjs/bin/phantomjs --version', $output, $code);
var_dump($code, $output);

And its output:

int 0
int 0
int 127
int 127
array (size=2)
  0 => string 'v0.10.29' (length=8)
  1 => string 'lrwxrwxrwx 1 root root 43 Jul 15 18:00 /usr/local/node/node-default/bin/phantomjs -> ../lib/node_modules/phantomjs/bin/phantomjs' (length=128)

I can run the command from my terminal and running the above code from PHP's interactive shell (php -a) outputs all 0 return codes and the following for the final output:

array(4) {
  [0] =>
  string(8) "v0.10.29"
  [1] =>
  string(128) "lrwxrwxrwx 1 root root 43 Jul 15 18:00 /usr/local/node/node-default/bin/phantomjs -> ../lib/node_modules/phantomjs/bin/phantomjs"
  [2] =>
  string(5) "1.9.7"
  [3] =>
  string(5) "1.9.7"
}

Since the target executable's permissions are 777, what could so be different about these environments that's causing php -a to execute PhantomJS just fine whereas my website's controller cannot?

Upvotes: 2

Views: 2592

Answers (2)

Steven Surowiec
Steven Surowiec

Reputation: 10220

I know it's a bit late but I just burned a lot of time investigating this exact issue. For me the problem was that when executed through apache the environment was slightly different so node wasn't found. I had to put /usr/local/bin/node in the exec call and then it worked.

Upvotes: 2

Lander
Lander

Reputation: 3437

I'm not sure if it's simply a permissions error or what, but after further discussion with @Athafoud I've decided to not use npm to install the phantom and instead just download the binary from their site. This works just fine for whatever reason.

Upvotes: 1

Related Questions