2

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
m.ed
  • 21
  • 1

1 Answers1

0

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.

Alex Forbes
  • 2,452
  • 2
  • 20
  • 26