How to finish http response and do further process

2019-07-21 16:01发布

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?

标签: php http
4条回答
神经病院院长
2楼-- · 2019-07-21 16:18

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.

查看更多
等我变得足够好
3楼-- · 2019-07-21 16:31

You could take a look at Run PHP Task Asynchronously which is pretty much what you want to accomplish.

查看更多
家丑人穷心不美
4楼-- · 2019-07-21 16:35

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
查看更多
Anthone
5楼-- · 2019-07-21 16:40

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

查看更多
登录 后发表回答