2015-08-15 136 views
-1

我可以運行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); 

?> 
+0

你能顯示你的PHP代碼嗎? – Austin

+0

添加了php代碼 – aruth

+1

嘗試檢查錯誤。 '$ output = array(); $ returnCode = null; exec($ rrd,$ output,$ returnCode);的print_r($輸出);回聲「返回代碼是$ returnCode \ n」;'看看會發生什麼。 – Austin

回答

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

+0

需要在代碼之前包含任何phantomjs文件 –