I am trying to check for syntax error of a php file using shell commands, its working fine in Windows (WAMP) but on linux the process created by shell commands exec/shell_exec/popen etc never terminates thus causing apache to hang while this process gets forcefully killed by me. also no output is generated after killing the process.
my test script is
file test.php is sample one line php file for testing only which contains
<?php
$test['arr'] = 'bla';
?>
and the code by which i try to check syntax error is:
$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;
also tried using function 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;
please someone point me where i am doing wrong and why process created by shell commands never ends itself in linux, i tried searching lot about this problem but i get no result.