Search code examples
phppythonsystemexecnohup

PHP Calling Server Scripts - WILL NOT CONTINUE after call


Right, I am calling a Python script in a PHP script. This PHP script needs to continue after the Python script has been called.

I have tried all of the following, yet PHP insists on waiting until the script has responded.

All tried:-

system('nohup python /home/process/script.py -i '.escapeshellarg($location).' &');
system('nohup python /home/process/script.py -i '.escapeshellarg($location).' 2>&1 &');
system('nohup python /home/process/script.py -i '.escapeshellarg($location).' < /dev/null 2>&1 &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' 2>&1 &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' < /dev/null 2>&1 &');

Also tried with passthru and without nohup.

Any help greatly appreciated.


Solution

  • Quoting the exec doc:

    If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

    You should try this instead:

    exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' &>/dev/null &');