php exec/shell_exec/system/popen/proc_open runs calling script itself infinite number of times on linux

后端 未结 1 1960
离开以前
离开以前 2021-01-14 00:24

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 whic

1条回答
  •  梦毁少年i
    2021-01-14 01:05

    After 2 days of headache and lots of googling... i found the solution in the link 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

    It was PHP CGI version which reads script name from the environment thus causing my calling script to run infinite number of times or untill the maximum number of allowed process or till whole memory was consumed.

    The solution as simply using command php-cli instead of command php.

    i replaced below line in my code

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

    with

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

    and now everything is fine.

    I hope it'll help someone. I've also changed the title of this question so that others people can easily find the solution of same problem in google.

    0 讨论(0)
提交回复
热议问题