我有一个脚本,它使用php -l检查php文件中的语法错误。它在windows中运行良好,但在Linux中提供了不正确的输出:
正在检查是否存在语法错误的文件exec_ip.php的内容是(它有需要检查的语法错误):
<?php
$arr['12] = 'asd';
?>
剧本是:
$slash = file_get_contents('exec_ip.php');
//echo $slash;
$tmpfname = tempnam("tmp", "PHPFile");
file_put_contents($tmpfname, $slash);
exec("php -l ".$tmpfname,$error);
$errtext = '';
foreach($error as $errline) $errtext.='<br>'.$errline;
unlink($tmpfname);
echo 'ERR:'.$errtext;
WINDOWS (WAMP) {CORRRECT}的结果:
ERR:
Parse error: syntax error, unexpected T_STRING, expecting ']' in C:\WINDOWS\Temp\PHP1F1.tmp on line 2
Errors parsing C:\WINDOWS\Temp\PHP1F1.tmp
LINUX中的结果(Centos/cPanel) {未知输出}:
ERR:
Content-type: text/html
ERR:
Content-type: text/html
ERR:
Content-type: text/html
ERR:
Content-type: text/html
ERR:
Content-type: text/html
ERR:
Content-type: text/html
ERR:
Content-type: text/html
ERR:
Content-type: text/html
ERR:
... too many same above lines
请有人帮助我,并指出为什么它提供不正确的输出在linux生产服务器。我也尝试使用shell_exec、popen、proc_open、system来代替exec,但它们都有相同的行为。我想找出过去两天的根源.请帮帮忙
编辑:有时我会看到以下错误日志"PHP : exec():无法在/home/user/public_html/exect.php第5行中分叉-l /tmp/PHPFileI4T43l“。我认为它是在递归执行命令本身,在每个递归上创建一个新进程,但无法得到原因。
发布于 2014-03-06 18:40:45
经过两天的头痛和大量的谷歌搜索..。我在链接http://www.mombu.com/php/php-5-forum/t-24759-exec-or-system-et-all-cause-an-infinite-loop-of-starting-requested-program-8469354.html中找到了解决方案
它是PHP版本,它从环境中读取脚本名,从而导致调用脚本运行无限次或直到允许进程的最大数量或直到整个内存被消耗为止。
该解决方案只是使用命令php而不是命令php。
我在代码中替换了下面一行
exec("php -l ".$tmpfname,$error);
使用
exec("php-cli -l ".$tmpfname,$error);
现在一切都好了。
希望能帮上忙。我还更改了这个问题的标题,以便其他人可以很容易地在谷歌找到相同问题的解决方案。
https://stackoverflow.com/questions/22225522
复制相似问题