2

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?

compile-fan
  • 16,885
  • 22
  • 59
  • 73
  • Sending an email doesn't take long, especially if you're handing off to a local mail server. How complicated is the message body? – Marc B Mar 17 '11 at 14:46
  • possible duplicate of [close a connection early](http://stackoverflow.com/questions/138374/close-a-connection-early) – Mark Amery Nov 21 '14 at 22:58

4 Answers4

1

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

Community
  • 1
  • 1
Johann du Toit
  • 2,609
  • 2
  • 16
  • 31
0

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.

Ikke
  • 99,403
  • 23
  • 97
  • 120
0

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
DhruvPathak
  • 42,059
  • 16
  • 116
  • 175
0

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

osm
  • 4,186
  • 3
  • 23
  • 24