2014-03-05 22 views
2

我想檢查使用shell命令的php文件的語法錯誤,它在Windows(WAMP)中工作正常,但是在linux上由shell命令創建的進程exec/shell_exec/popen等永遠不會終止,從而導致apache掛起,而這個過程被我強行殺死。殺死該進程後也不會生成輸出。php exec或shell_exec在腳本執行結束後沒有終止它的進程在linux中

我的測試腳本是

文件test.php的僅用於測試包含

<?php 
$test['arr'] = 'bla'; 
?> 

,並通過我嘗試檢查語法錯誤的代碼示例一行php文件是:

$slash = file_get_contents('test.php'); 
$tmpfname = tempnam("tmp", "PHPFile"); 
file_put_contents($tmpfname, $slash); 
exec("php -l ".$tmpfname." 2>&1",$error); //also tried shell_exec but same behaviour 
$errtext = ''; 
foreach($error as $errline) $errtext.='<br>'.$errline; 
unlink($tmpfname); 
echo $errtext; 

也使用功能popen方法

$slash = file_get_contents('test.php'); 
$tmpfname = tempnam("tmp", "PHPFile"); 
file_put_contents($tmpfname, $slash); 
$handle = popen("php -l ".$tmpfname." 2>&1", 'r'); 
$errtext = fread($handle, 2096); 
pclose($handle); 
unlink($tmpfname); 
echo $errtext; 
嘗試

請有人指出我在哪裏做錯了,爲什麼由shell命令創建的進程永遠不會在linux本身結束,我試圖尋找很多關於這個問題,但我沒有得到任何結果。

回答

相關問題