In my case I need to echo开发者_运维问答 a flag to client side and send an email .
Now client side needs to wait until the email is sent...
But I want to separate these two steps,how to do that?
You could take a look at Run PHP Task Asynchronously which is pretty much what you want to accomplish.
You could take a look at Gearman
Gearman is a system to farm out work to other machines, dispatching function calls to machines that are better suited to do work, to do work in parallel, to load balance lots of function calls, or to call functions between languages.
Have another php file to send emails, and call it with some parameters using shell_exec . You can also call the URL on command line using CURL with some parameters.
That would work fine, you can track your email success status in the target file.
pseudo code:
my main file :
php stuf...
shell_exec("usr/bin/php mySecondfile.php someParam > /dev/null 2>/dev/null &");
other stuff continued.
send SUCCESS
You can use pcntl_fork() function for that. With pcntl you can fork processes to child process with different pid.
http://php.net/manual/en/function.pcntl-fork.php
精彩评论