Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have a Windows 2008 Server running PHP 5.2.11 on IIS 7.5

When any script on the server calls a mail() function it presents no errors and sends the email nearly instantly. However, the server will "hang" for about 60 to 90 seconds until it starts sending information back to the browser. This delay seems to be longer if mail() has not been called in the preceding 2 minutes.

I viewed this issue in the Chrome developer tools "network" tab and it just says "waiting" for that entire period. Once that delay is over, all of the information is sent correctly to the browser and the page renders normally.

Potentially relevant portions of the phpinfo() output:

Internal Sendmail Support for Windows - enabled
sendmail_from - no value
sendmail_path - no value
SMTP - mail.samedomain.com
smtp_port - 25
mail.force_extra_parameters - no value
share|improve this question
add comment

1 Answer

PHP mail() is pretty inefficient to start with, the PHP manual itself says:

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.

Not particularly relevant when the number of messages is 1, but there is another potential gotcha:

The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

Thus unlike the Unix version it can't fire at a local daemon, it has to wait for the network.

I am not a coder, but this is clearly a coding problem. It's likely that the mail function is expecting a certain response from your MTA and not getting it, 60 seconds sounds like a pretty standard timeout value. Also your frontend UI code should not be waiting on mail(), which is typically a background process. It's not too difficult to do this asynchronously.

In summation, you could probably fix this at the MTA level (maybe by setting up a local one on the IIS server), but it's really a coding problem. Suggest nicely to your developers that they don't use mail() when performance is important, and don't block your frontend code when you're waiting for it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.