1

I am working on a project, where i need to send notifications to some users, i am using smtp settings with zend framework 2 Zend/Mail library. I have turned on tls and open ssl in php.ini settings.

The issue is the notifications are way too slow and usually when 5 or more users are using the application at the same time, i am getting a time out error.

Can i make this email send faster using any configuration ?

Let me know if there is some configuration can be used.

Suhel Meman
  • 3,702
  • 1
  • 18
  • 26
Varun Maggo
  • 1,224
  • 2
  • 13
  • 27
  • That's a thing where you've got to make use of good Debugging-Tools and track down where exactly your bottlenecks are. – Sam Apr 24 '13 at 06:58
  • Sam thanks for looking at this issue, before using email notifications, the things were working good, but post email notifications things are way too slow. – Varun Maggo Apr 24 '13 at 07:14
  • I just want to speed up the email notifications. plz help. – Varun Maggo Apr 24 '13 at 07:14
  • It's pretty much impossible without knowing what EXACTLY is causing the bottleneck ;) You HAVE TO debug to know what's running slow! – Sam Apr 24 '13 at 07:40
  • If i comment the mail function it submits the page in 1.10 seconds, and after uncommenting the mail function the pages takes 6-7 seconds to submit. so this is mail function which is the bottleneck ;) – Varun Maggo Apr 24 '13 at 07:45
  • You should look at your web server settings, possibly this is where the bottleneck is in handling more than 5 concurrent requests, which is pretty low for a web server. what settings will depend on the webserver, and the setup being used. – Andrew Apr 24 '13 at 07:48
  • The mail function does a lot. Connecting to the server, preparing the mail, etc.. etc... "the mail function" is not the bottleneck - if it really is the actual `php mail()` then it's a thing of server configuration – Sam Apr 24 '13 at 08:38
  • Did you find any solution? – Hasina Dec 12 '17 at 13:10

3 Answers3

1

Why not add the emails to a queue and actually send it from a different process? I assume it would not be a problem if the mail is sent 1 minute after the submit.

3rd party systems are always a risk when you wait for them. Therefore i try to minimize waits for 3rd party systems by running these things in a seperate process

nvanesch
  • 2,540
  • 14
  • 25
  • make sense, can you give me a link to any blog post, from where i can get reference. If you could give me a blog post link it would be great. – Varun Maggo Apr 24 '13 at 10:11
  • 1
    you might want to look at http://stackoverflow.com/questions/8668038/in-php5-wish-to-send-email-in-different-process or http://pear.php.net/package/Mail_Queue – nvanesch Apr 24 '13 at 11:11
1

If I had to bet, I'd bet that there's a lot of latency to your SMTP server. You say you're using google for SMTP, which I'm not familiar with, but that's going to be a far away server (relative to like, and SMTP box on your network). On top of that, you say you're running SMTP over SSL. SSL is a complex protocol with a lot handshaking before the connection is even established. This means the network latency between your server and the SMTP service is multiplied as the two machines do the SSL handshake dialog. Overall, it's not a great setup.

Some kind of work-queue would help. So your web-bound processes just stick stuff jobs on some queue, and some workers do their best to keep up. You could implement something like that in PHP (you might consider something like gearman or beanstalkd to provide the actual queueing).

But there's another, very specialized, option. Just use your local sendmail (assuming you're on a unix-type box). Sendmail (and the various drop-in replacements MTAs) maintains it's own queue. This stuff has been around for years and is quite solid. You can configure your MTA to pass the mail on through your current SMTP setup, too.

The difference will be that instead of your PHP script talking to the remote SMTP server, it just talks to a local service which just takes the mail, queues it, and returns in practically no time flat. It holds the mail in the queue until it can manage to send it along via SMTP.

Plain old local sendmail will go a long way towards getting you fixed up. If you're on a Windows server, I'm not sure what your options are. There must, at the very least, be a local SMTP server you can run that can be configured to relay all the mail out via SSL to google.

timdev
  • 61,857
  • 6
  • 82
  • 92
0

I know my ISP I use at home doesn't actually allow me to send e-mails at all. It was a very frustrating day figuring out what had stopped working. Eventually I tracked it down and realised if I was at home I was getting timeout errors, but if I was in the office it was sending fine.

deadtoy
  • 43
  • 4