phantomjs不工作使用exec
问题描述:
我可以运行phantomjs-netsniff代码在终端(作为根)创建har文件,但是当我使用php执行它时,它会返回确实创建har文件,但零咬合。两次执行相同的代码。phantomjs不工作使用exec
我已禁用安全模式在PHP中,生成文件夹的哈希777权限。我错过了什么。
我的操作系统是centos 64位。我用https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2进行安装。
PHP代码
<?php
$rrd= 'phantomjs /var/www/xxx/netsniff.js "http://www.wiki.com" > /var/www/xxx/xx/xx.har';
exec($rrd);
?>
答
您应经常检查错误;这可以告诉你什么错误:
$output = array();
$returnCode = null;
exec($rrd, $output, $returnCode);
print_r($output);
echo "Return code was $returnCode\n";
从你的评论,你说你得到的返回码127,这通常意味着“命令未找到”。你的路上是phantomjs
?如果您键入which phantomjs
作为PHP运行的用户,您会得到什么?避免这种情况的简单方法是仅指定命令中二进制文件的完整路径,即在命令字符串中使用/path/to/phantomjs
而不是仅使用phantomjs
。
+0
需要在代码之前包含任何phantomjs文件 –
你能显示你的PHP代码吗? – Austin
添加了php代码 – aruth
尝试检查错误。 '$ output = array(); $ returnCode = null; exec($ rrd,$ output,$ returnCode);的print_r($输出);回声“返回代码是$ returnCode \ n”;'看看会发生什么。 – Austin