I've a script which check for syntax error in php file using php -l . It works fine in windows but gives incorrect output in Linux:
content of file exec_ip.php which is being checked for syntax error is (it has syntax error which is to be checked):
<?php
$arr['12] = 'asd';
?>
and the script is:
$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;
RESULT IN 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
RESULT IN LINUX (Centos/cPanel) {UNKNOWN OUTPUT}:
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
Please someone help me and point me why it is giving incorrect output in linux production server. I've also tried using shell_exec, popen, proc_open, system in place of exec but all has same behavior. I am trying to trace the root cause from past 2 days... please help
EDIT: Sometimes i see following errorlog "PHP Warning: exec(): Unable to fork [php -l /tmp/PHPFileI4T43l] in /home/user/public_html/exect.php on line 5". I think it is recursing exec commands itself creating a new process on each recursion, but couldn't get the cause of it.