Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating new thread(?) in PHP [duplicate]

Possible Duplicate:
php execute a background process
how can I achieve a task that should be done in thread in php

I have this PHP script that takes a little long to process. However I don't want the viewer to wait for the script to finish. I want him to be able to continue browsing and/or close the browser. Yet I want the script to continue to work... How can I do this? Is there way to create some sort of thread that will allow such a thing?

p.s. I really don't want to re-write the script in another language and execute it via os.

like image 302
JohnRoach Avatar asked Dec 04 '22 06:12

JohnRoach


1 Answers

If you can run your script from the CLI, you can "fork" it into a background process from the script your web server is serving by calling something like:

exec('php your_script.php > /dev/null &');

This will allow the page to finish loading, but keep your_script.php running.

like image 115
nnevala Avatar answered Dec 05 '22 19:12

nnevala