Using email queue and php exec () is one of the best ways.
It will start when necessary (avoiding the use of CRONs), quickly, because it is caused by the background and immediate.
1. Email queue. Take all the fields in the MySQL table with the insert, something like:
$queryIN="INSERT INTO email_queue (date,subject,body,destination,idle) values (...)"; mysql_query($queryIN);
This is important because you will need an independent background process, so it is also a good idea to register and audit all outgoing emails.
2. PHP exec (). After pasting into MySQL, the time to call as an external execution is:
exec("wget -qO- http://domain.com/index.php?process_email_queue=1 &> /dev/null &");
- Please note: for output and invocation as a background process, parameters from wget -q0- and &> ... / dev / null & are required.
3. The same script file index.php or another to handle the call to the queue:
Thus, it will call our index.php (you can use a different name file) and process the outgoing ones:
if ($_GET['process_email_queue']==1) { ...code for sending idle emails queue... }
Perhaps you need to touch on some php.ini options for exec (), this is not a big problem.
Once everything works correctly, you will offer the best site navigation and email for quick response and zero waiting.
In some cases, you will go from waiting from direct mail 2.60 seconds to queue-exec-background 0.024 secs, i.e., x11 improvements are faster.