views:

16

answers:

3

As I see, pear only persist the connection during the execution of the script, then it releases...

+1  A: 

No, you can only persist over multiple calls to the send() method.

Sam Dark
Yeap, I thought that... Do you have experience over Daemon services?
paterlinimatias
http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/
Sam Dark
A: 

There are two ways to address your issue:

  1. Connection pooling
  2. Pass the work off to a background process

Honestly, there's almost never a reason to send email directly from a PHP web request -- email isn't guaranteed to be low latency anyway, so if it takes a little longer to send email in the background, it's not a big deal.

As such, the best and simplest approach is simply to store the email to fast, local storage (maybe a job queue like beanstalkd), and then have a completely separate process checking that queue for work, and handling the task of the actual SMTP request. That long-running script can even hold a single SMTP connection open, if you please.

Frank Farmer
A: 

Your best solution is to install an MTU like sendmail, postfix or QMail and then send your mail locally to it, this will lower the latency of the connection on your script to the minimum possible without having to mess with connection pooling or a background daemon.

Neel