PHP and shell_exec

前端 未结 6 1122
余生分开走
余生分开走 2021-01-22 14:06

I have a PHP website and I would like to execute a very long Python script in background (300 MB memory and 100 seconds). The process communication is done via database: when th

6条回答
  •  故里飘歌
    2021-01-22 15:05

    First off set_time_limit(0); will make your script run for ever so timeout shouldn't be an issue. Second any *exec call in PHP does NOT use the PATH by default (might depend on configuration), so your script will exit without giving any info on the problem, and it quite often ends up being that it can't find the program, in this case python. So change it to:

    shell_exec("/full/path/to/python /full/path/to/my/script");
    

    If your python script is running on it's own without problems, then it's very likely this is the problem. As for the memory, I'm pretty sure PHP won't use the same memory python is using. So if it's using 300MB PHP should stay at default (say 1MB) and just wait for the end of shell_exec.

提交回复
热议问题