Re: mail() takes too much time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matthew Lasar wrote:
> I run pretty simple mail group distribution program that uses php/mysql
> and the mail() function. I adapted it from an open source script. Most
> of the time it runs well. But it does take a while to run through all
> 150 members of the list. So I'm half glad that I don't have a list of
> 1000 people or more.
> 
> Any way to optimize the mail function in terms of speed? Probably too
> vague a question, sorry.

Yeah it is fairly vauge.

I guess one obvious way is to ask whether or not you send the same mail
content to people but just do it 150 times? Or whether you customise the
mail to each person putting in e.g. their name at the top etc. If the
former then you can send the mails in batches of about 30-50 at a time
using the BCC header rather than a direct To header (set the To address
to e.g. yourself or a dummy address that works but is a bitbucket). That
way there will be considerably less calls to mail() to process.

The other way would be to write the mails to a database and process them
later. You could write a special cronjob that runs every few minutes and
pushes them out in the background. It could run every minute or two
(with file locking to prevent more than one instance at a time) and
either process all mails it can or just do about 50 of them and then
quit and leave the rest for the next run. Obviously you have to manage
it to make sure that it can physically catch up with how many mails are
being generated but this isn't too hard.

There are lots of other ways too - I've even seen some people program a
MySQL UDF to send mail and let the database do the work, but I would
have serious doubts about that approach for this use!!

Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux