-1

i can run phantomjs-netsniff code to create har file in terminal (as root) but when i execute it using php it returns does create har file but with zero bites. same code executed both times.

i have disabled safe-mode in php, 777 permission on har generating folder. what i have missed.

my OS is centos 64 bit. and i used https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2 to install.

php code

<?php

$rrd= 'phantomjs /var/www/xxx/netsniff.js "http://www.wiki.com" > /var/www/xxx/xx/xx.har';
exec($rrd);

?>
4

1 回答 1

0

你应该经常检查错误;这可以告诉你出了什么问题:

$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在命令字符串中。

于 2015-08-15T18:23:45.737 回答