0

I want to have a PHP program call a python program and have it run the background. When I call this from the shell nohup python3 automation.py args >/dev/null 2>&1 & , everything runs fine. I run top and jobs and I can see that it is executing. The script finishes successfully.

Now I would like this script to be called from a PHP program and then run in the background, so I am using this command, which is the same above. For the program not to hang, I output it to null. exec('nohup python3 automation.py args >/dev/null 2>&1 &')

Everything runs fine for awhile when I administer a top but then it dies after a few seconds and I am left scratching my head to figure out why. How do I troubleshoot this?

Alex
  • 41
  • 5
  • Check out: https://stackoverflow.com/a/38179655/6472849 – brice Jul 04 '21 at 20:52
  • @brice I tried that and it didn't work for me. I have no problem calling the script from php and executing, however the python process dies prematurely. When I call it from the command line with the same args however it runs just fine. – Alex Jul 04 '21 at 21:45

1 Answers1

0

Problem solved. The linux user that PHP is used when commands are executed is www-data. That user didn't have write permissions for the file. To log in as www-data for testing, run this su -s /bin/bash www-data. Any command you execute in the shell should be equivalent to calling it from PHP.

Alex
  • 41
  • 5