Php exec / shell_exec / system / popen / proc_open runs a script call itself an infinite number of times on linux

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, , .

+4
1

... 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 CGI, script , , script , .

php-cli php.

i

exec("php -l ".$tmpfname,$error);

exec("php-cli -l ".$tmpfname,$error);

.

, -. , google.

+9

Source: https://habr.com/ru/post/1530418/


All Articles