Sample Header Ad - 728x90

php script: shell_exec('nohup /usr/bin/python3 -u /location/script.py > /location/script.log & : Script terminates after 5 seconds but should not

0 votes
0 answers
34 views
I have a PHP Script with the command shell_exec('nohup /usr/bin/python3 -u /location/script.py > /location/script.log &'); This PHP Script is called via ajax, the script runs, logfile is created, output is written to logfile, but the python script terminates after 5-6 seconds. The same command runs flawlessly in a SSH terminal. The PHP is an Ajax-called script, there is no issue with the Ajax call. I can tell because the logfile is created and the first few output lines are correct, but then the python script terminates. Whatever I did, it did not change, I tried prefixing with sudo -u username and sudo -u www-data, appending & disown &, changed the user that runs apache2, but all attempts didn't change the result. The python3 code is working correctly, because i can manually start the command from SSH and it runs flawlessly. There is no stacktrace in the logfile, it just stops. It vanishes from ps aux | grep script I need the Ajax method of calling the script, what can I do? Running on Debian 12
Asked by cli (1 rep)
Apr 13, 2025, 02:57 PM
Last activity: Apr 13, 2025, 04:01 PM