Call another PHP script and return control to user before the other script completes

Solution 1:

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 Section

"If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends."

Solution 2:

Other solution :

  • Your script put a token somewhere (DB/filesystem) when a mail needs to be sent (token may contain data for mail generation)
  • A daemon (can be written in php) runs in the background looking for tokens and "eats" them to send mail

I use this kind of solution quite a lot ...

Solution 3:

I am using jQuery and AJAX to do stuff like this for PHP scripts which take long time.