【发布时间】:2014-04-09 03:36:10
【问题描述】:
我有一个脚本,它使用 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) {正确}:
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,但它们都有相同的行为。我正在尝试追踪过去 2 天的根本原因...请帮助
编辑: 有时我看到以下错误日志“PHP 警告:exec(): Unable to fork [php -l /tmp/PHPFileI4T43l] in /home/user/public_html/exect.php 在线5"。 我认为它是递归 exec 命令本身在每次递归时创建一个新进程,但无法得到它的原因。
【问题讨论】: