I'm actually trying to apply this to a script that sends email. The sending email part takes a few seconds which is too long. What I want is for the first script to do its stuff and trigger another script (which sends the Email), but I want the first script to return control to the user without waiting for the second script to send the email.
Options that I have considered:
Cron Job: For this I'll have to have a cron job run something like every 2 mins. Not feasible!
PHP script activating a cron job which deactivates itself when done: Well ok, but how do I do this? Can PHP do this?
You can also call the shell and manually call the PHP file. No cron required and no waiting.
http://www.php.net/manual/en/function.exec.php
From the
Notes
SectionOther solution :
I use this kind of solution quite a lot ...
What you want to use is something called beanstalkd
Details: How can I get a list of all jobs in a beanstalk tube?
It will allow you to queue up jobs (do 1, then 2, then 3. then 4) you can even distribute these tasks across servers (yes for php jobs!).
I am using jQuery and AJAX to do stuff like this for PHP scripts which take long time.