views:

81

answers:

4

It takes around a couple of seconds for my app to execute the code to send an email right now on a test server with nothing much else running. Not sure if this is typical/expected. I'm also using the php framework Kohana's email helper and not php's mail directly out of convenience if that matters. Is it always just better to schedule a cron job to send emails every 5 min or so? Or should I be able to send emails immediately and I'm just not doing something right?

What the script does is insert a row into the db and notifies the relevant group that the row was created. The groups are usually < 20 people so I just do a loop calling Kohana's email helper each time for each member of the group.

+2  A: 

Not sure about the implentation of the Kohana helper, but here is what the php doc tells :

Note: It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient. For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Boris Guéry
+2  A: 

http://swiftmailer.org/ is an excellent and reliable mailer. Maybe an alternative approach is the right answer.

Christopher Altman
It's also the *de facto* standard for mailing in Kohana. +1
alex
A: 

Something is not right, for groups of less than twenty users, it should be speedy. > 100 would garner slower processing time.

Look into your server setup. Or, use the IMAP functions...

Ixmatus
A: 

For the quickest solution look into gearman You basically send the request to send the email into the gearman queue, and the rest of your script can run while Gearman completes the email part of your script in the background

pitch_invasion