tundoopani tundoopani - 4 years ago 75
PHP Question

How can I run a PHP script in the background after pushing some data to it?

I have an upload script that uploads images to a server. I need a script to run in the background after the image is uploaded and moved by

move_uploaded_file()
, but I need to send a filename and path to that file to the script (pretty much send some data).

How can I run a PHP script in the background after some data has been sent to it?

Notes: The files are uploaded via XMLHttpRequest.

Answer Source

First read this

php exec command (or similar) to not wait for result

It is basically pointing out that you need to create a script that takes two params ( filename, path)

Then you need to use the exec function

Edit:

As pointed out by Brent Baisle in the comments below, "nohup" must be added infront of the script to execute independently (with a different parent pid)

exec('noup php scriptyoucreated.php '.$filename.' '.$path.' > /dev/null 2>&1 &');

This writes the output to dev/null, php should not block at this point, i have not tried, but in theory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download