The zend framework 2 send email is too slow(google smtp server )

时光毁灭记忆、已成空白 提交于 2019-12-24 16:29:53

问题


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.


回答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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/16185240/the-zend-framework-2-send-email-is-too-slowgoogle-smtp-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!