I created a Email-Queue database table. I will insert all Emails my PHP application needs to send into this table.
Another PHP script will then look for all unsent Emails and sends them.
I run this script using cronjobs. Unfortunately cronjobs can run only at a maximum of once per minute. So in the worst-case a user has to wait one minute until his Email is really going to be sent.
My current idea for a workaround is calling the script with an addtional sleep parameter and duplicating the cronjobs.
Example:
* * * * * curl emails.php?sleep=0 >/dev/null 2>&1
* * * * * curl emails.php?sleep=10 >/dev/null 2>&1
* * * * * curl emails.php?sleep=20 >/dev/null 2>&1
* * * * * curl emails.php?sleep=30 >/dev/null 2>&1
* * * * * curl emails.php?sleep=40 >/dev/null 2>&1
* * * * * curl emails.php?sleep=50 >/dev/null 2>&1
In the above example the script would run every 10 seconds. The first line of the emails.php Script would be:
sleep($_REQUEST['sleep']);