Re: Individual bulk e-mails - performance question



Hello,

on 08/30/2008 02:40 PM Merlin said the following:
I am running a travel community where users want to get informed on changes inside different groups they have subscribed to.

At the moment I am doing this with a for loop that generates an individual e-mail sent to them via phpmailer. That works, however the submit of the content upload form (that triggers the e-mail notification) now takes several seconds, as more and more users subscribe.

I am thinking about placing the info on the individual e-mail inside a ascii txt file that will be read by a cron job which will send the e-mail instead. Something like every 5 minutes reading it line by line and then after sending it removing the line.
e.g:
for:bla@xxxxxxx; body:individual
for:new@xxxxxxxxxxxxx; body:other email

Does this sound like a plan? Or do you believe that there are better ways doing it? I could imagine that I would run into problems a few months from now if for example the cron job will be triggered a second time, while the first one has not finished.

Any ideas or suggestions? Thank you for any help.

While it is a good idea to off-load e-mail delivery to a script run from cron, it seems odd that each mail takes several seconds to deliver.

I suspect that you sending messages in a less efficient way. Maybe you are queueing messages using SMTP (which is the slowest way to queue messages) or you are using sendmail on your system and it is configured by default to attempt to deliver the messages immediately, making your PHP script hang while the message is not accepted by the remote server.

There are much better ways to do it by just telling the mail system to queue the messages without holding on the PHP script.

On the other hand, if the time it takes build your messages but the messages have the same contents for all the receipients, you can also use some good e-mail components with caching support.

In that case, I recommend that you use for instance this MIME message class that provides message body caching support, so you can send messages to different receipients and cache the building of message body parts and avoid overhead when sending to a new receipient.

It also provides different means to send messages and solve the overhead of message delivery by forcing the messages to queue by your local and be delivered later whenever possible, so your PHP script is freed to send messages to other recipients.


http://www.phpclasses.org/mimemessage


--

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
.



Relevant Pages

  • Re: Persistent connections
    ... persistent socket. ... If I launch it as a CRON job, ... Let's set the PHP script aside, ...
    (comp.lang.php)
  • Re: [PHP] PHP Speech
    ... Your hosting service provides the capability to turn html text to speech, ... The php script is history after presenting ... The only way I can see is to set up a cron job to delete all wave files ... having a tough time with paid gigs now and find no time to focus on ...
    (php.general)
  • Setting up a cron job from within a PHP script
    ... I am trying to set up a cron job, from within a php script. ... fwrite; ... //demo is the user name for the demo directory/subdomain ...
    (comp.lang.php)
  • Re: create a cron job of php script using webmin
    ... > i m using webmin to create a cron job of a php script. ... means that there's no PATH set up, so you either need to add in the ...
    (comp.lang.php)
  • Re: Arguments in Cron Jobs
    ... GoodMan wrote: ... I was trying to run a simple cron job on my a certain php script I ... It looks like you're trying to use URL syntax. ...
    (comp.unix.admin)