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/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php