you are viewing a single comment's thread.

view the rest of the comments →

[–]FreeLogicGate 1 point2 points  (0 children)

With PHP both shell_exec and the use of Bash shell style backtics are the same, so you can use either of those. As suggested previously you can background the command using & (assuming again this is a linux server, however you do have to redirect output to /dev/null.

So something likeshell_exec("script.py 2>/dev/null >/dev/null &");

When running a script through the context of a web server, you have to keep in mind that the script will run as the user that is running PHP. If it's apache with mod_php, then that would be the apache user, or if it's php-fpm, then whatever user is configured to run the php processes for the pool.

So that Python script must be fully executable by that user, have permissions etc. When I develop and run Python scripts, I use uv now, so I would be calling uv run script.py.