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);
?>
You should always check for errors; this can tell you what is going wrong:
$output = array();
$returnCode = null;
exec($rrd, $output, $returnCode);
print_r($output);
echo "Return code was $returnCode\n";
From your comment, you say you get return code 127, which usually means "command not found". Is phantomjs
on your path? If you type which phantomjs
as the user that PHP is running as, what do you get? An easy way to avoid this is to just specify the full path to the binary in the command, i.e., use /path/to/phantomjs
instead of just phantomjs
in the command string.