简体   繁体   English

使用exec()运行PhantomJS时返回错误代码127

[英]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. 在我的Vagrant环境中(尚未在服务器上进行测试),当尝试从我的网站的一个控制器中使用exec()运行PhantomJS时,始终出现错误。

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: 我可以从终端运行命令,并从PHP的交互式外壳程序( php -a )运行以上代码,输出所有0返回代码,并输出以下内容作为最终输出:

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? 由于目标可执行文件的权限为777,因此这些环境可能有什么不同,导致php -a可以很好地执行PhantomJS,而我网站的控制器却不能?

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. 对我来说,问题是,通过apache执行时,环境略有不同,因此找不到node I had to put /usr/local/bin/node in the exec call and then it worked. 我必须将/usr/local/bin/node放入exec调用中,然后它才起作用。

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. 我不确定这仅仅是权限错误还是什么,但是在与@Athafoud进行进一步讨论后,我决定不使用npm安装幻像,而是从其站点下载二进制文件。 This works just fine for whatever reason. 无论出于何种原因,这都可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM