I have a script that checks for a syntax error in a php file using php -l. It works fine on Windows, but gives the wrong output on Linux:
the contents of the exec_ip.php file that is checked for a syntax error (has a syntax error that needs to be checked):
<?php
$arr['12] = 'asd';
?>
and script:
$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 help me and tell me why it gives the wrong output on a Linux production server. I also tried using shell_exec, popen, proc_open, instead of exec, but everything has the same behavior. I am trying to trace the root cause in the last 2 days ... please help
: "PHP Warning: exec(): [php -l/tmp/PHPFileI4T43l] /home/user/public _html/exect.php 5".
, exec, , .