Re: Re: SMTP vs mail()

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

 



Hello,

on 01/11/2008 08:26 PM Richard Lynch said the following:
>>> Bearing in mind I haven't yet done any benchmarks, which do you
>>> think is
>>> faster - SMTP with multiple RCPT commands or the PHP mail() function
>>> (with it launching a separate sendmail process for each mail()
>>> function
>>> call)?
>> It depends on the platform you are running PHP.
>>
>> There is a myth by which people believe that using mail() is slower
>> than
>> using SMTP connections.
>>
>> Some of those people using PHP on Windows (especially for
>> development).
>> On Windows, mail() uses SMTP connections.
>>
>> On Linux/Unix, mail() uses sendmail or equivalent programs. These
>> programs use pipes to communicate, which are much faster than using
>> SMTP
>> TCP sockets.
>>
>> If you have your sendmail equivalent program properly configured, no
>> SMTP connection is used when queueing messages using the sendmail
>> program.
> 
> It may be possible to get sendmail to queue up the emails quickly, but
> they won't actually go out until much later, when the queue is run...

That is exactly how it works when you send a message via sendmail SMTP
server. The message is not delivered right away. If it was there is no
way for the SMTP server to return so fast.

If the SMTP server would wait to have the message delivered, it would
take a long time. Which is exactly what happens when you call the
sendmail program directly because its default delivery mode is to
attempt to deliver the message right away.

Anyway, that is irrelevant. What matters is that PHP is freed to send a
message to the next recipient or to do other stuff.

That is why configuring it to defer the delivery is a much better idea,
than waiting for the message to be processed.

Anyway, the actual delivery may take days to happen because often MTA
needs to retry many times, especially now that many SMTP servers are
using grey listing. It does not make much sense to wait for any delivery.

Still, if you are concerned with waiting for the queue manage to process
the messages, the delay between queue runs is configurable. If you are
still not happy you can configure sendmail queue manager to keep running
persistently.

Still if you want the fastest delivery in the world, you can skip
queueing and talk directly to the final SMTP server. That is what the
direct_delivery mode of this SMTP class does. I use it for deliverying
really urgent messages. It uses PHP only, there is no sendmail or any
MTA in the middle. That is why it is the fastest solution. The class is
the MTA itself.

http://www.phpclasses.org/smtpclass

Actually I use it with the wrapper of the MIME message class for SMTP
because I still need to compose the messages conforming to the e-mail
standards, and that is something hard to do by hand.

http://www.phpclasses.org/mimemessage

This class comes with mail() function replacement named urgent_mail()
that uses the direct delivery mode. If the message is delivered to the
final SMTP server for some reason, it drops it in the local MTA using
the mail() function.

For deliverying non-urgent messages, I use the default delivery method
that uses the mail() function, which pipes messages to the MTA via the
sendmail program or equivalent.

Actually, I do not use sendmail. I use qmail which has its queue manager
running all the time by default. Actually, I don't know if you can make
the qmail queue manager run only once in a while like with sendmail.

The class above also has a driver class to send message via sendmail.
That driver provides options to tell sendmail to queue the messages,
instead of waiting for the message delivery. Since I use qmail, it does
not matter because it always queue the messages.


> And I'd be interested to hear of an actual side-by-side comparison on
> comparable hardware where sendmail using pipes beats SMTP on a LAN.

I am not sure what you mean.

You see, when a message is received by a SMTP server, it is passed also
via pipes to the queue manager. The queue manager decides to send the
message to the final SMTP server via the SMTP client or just drop it in
a queue.

So, the message goes to the same destination, except that using SMTP is
the slow path, because the TCP overhead (think of DNS resolution, TCP
opening sockets, waiting for connections, TCP packet information stuff,
TCP error handling, TCP closing sockets, etc..).

TCP connections are not a good idea for local connections. That is why
under Linux/Unix there are Unix domain sockets which are basically pipes
for inter-program communication.


> If your SMTP server is halfway across the planet, well, yeah, then you
> got a problem right there...

What SMTP server? The final SMTP server associated to the domain of the
recipient?

You know you do not need a SMTP server to send messages. You just need
an MTA (Mail Transfer Agent). Once you queue the message in the MTA
queue, it will take care of the delivery.

-- 

Regards,
Manuel Lemos

PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/

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


[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