Re: Cron php & refresh
| From: | Per Jessen | Date: | Sun, 20 Apr 2008 11:34:16 +0000 |
| Subject: | Re: Cron php & refresh | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-273320@lists.php.net to get a copy of this message | ||
Jeffrey wrote:
> Per Jessen wrote:
>> Jeffrey wrote:
>>
>>> I'm working on an application that includes e-mail notifications of
>>> certain events. Because the application will have hundreds or
>>> thousands of users, I've designed it so that e-mail notifications
>>> are saved to a MySQL table. Then a regular cron job runs a php page
>>> to select the data from the table, put it into a mail() command and
>>> mail.
>>
>> Why not just send the notification at the time of the event? (I
>> assume you update the database at the time of the event).
>>
>>
>> /Per Jessen, Zürich
>>
>>
> Because in my experience, several hundred e-mails takes time to send,
> hence either the user leaves the page before all the mails are sent or
> the page times out before all mails are sent. And if there are
> thousands of e-mails, it will only get worse.
Sorry, I (wrongly) assumed 1 event = 1 email.
OK, then I'd stick to what you're doing - add the event to a queue (i.e..
your database), and poll this at regular intervals. I don't think you
need to worry about the number of emails sent per interval. Just let
your PHP script generate the sendmail commands and the email-text to
stdout, then pipe that to /bin/sh.
The output generated by your script would look like this:
sendmail -oi -r <fromaddr> <toaddr> ..... <<XXX
emailhdr
emailhdr
emailtxt
emailtxt
emailtxt
XXX
sendmail -oi -r <fromaddr> <toaddr> ..... <<XXX
etc
etc
/Per Jessen, Zürich