NGINX + PHP-FPM 502 相关事

NGINX + PHP-FPM 报 502 错误,我想大部分 SA 都遇到过吧。

502,是后端 PHP-FPM 不可用造成的,间歇性的502一般认为是由于 PHP-FPM 进程重启造成的。

在 PHP-FPM 的配置中存在这么一项:

How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
<value name=”max_requests”>500</value>

这段配置的意思是,当一个 PHP-CGI 进程处理的请求数累积到 500 个后,自动重启该进程。


一般在项目中,我们多多少少都会用到一些 PHP 的第三方库,这些第三方库经常存在内存泄漏问题,如果不定期重启 PHP-CGI 进程,势必造成内存使用量不断增长。因此 PHP-FPM 作为 PHP-CGI 的管理器,提供了这么一项监控功能,对请求达到指定次数的 PHP-CGI 进程进行重启,保证内存使用量不增长。

正是因为这个机制,在高并发的站点中,经常导致 502 错误,我猜测原因是 PHP-FPM 对从 NGINX 过来的请求队列没处理好。不过我目前用的还是 PHP 5.3.2,不知道在 PHP 5.3.3 中是否还存在这个问题。

目前我们的解决方法是,把这个值尽量设置大些,尽可能减少 PHP-CGI 重新 SPAWN 的次数,同时也能提高总体性能。在我们自己实际的生产环境中发现,内存泄漏并不明显,因此我们将这个值设置得非常大(204800)。大家要根据自己的实际情况设置这个值,不能盲目地加大。

话说回来,这套机制目的只为保证 PHP-CGI 不过分地占用内存,为何不通过检测内存的方式来处理呢?我非常认同高春辉所说的,通过设置进程的峰值内在占用量来重启 PHP-CGI 进程,会是更好的一个解决方案。

期待他的建议能在今后的 PHP-FPM 版本中实现。

— EOF —

《NGINX + PHP-FPM 502 相关事》有47个想法

  1. I just want to say I am just newbie to weblog and honestly enjoyed this blog. More than likely I’m likely to bookmark your site . You definitely have good well written articles. Bless you for sharing with us your web site.

  2. I simply want to tell you that I am all new to weblog and actually liked your page. Most likely I’m going to bookmark your site . You definitely come with great posts. Thanks for sharing with us your web page.

  3. I just want to mention I’m new to blogging and site-building and really liked your web blog. Likely I’m likely to bookmark your website . You surely come with excellent articles. Bless you for revealing your webpage.

  4. I simply want to tell you that I am just all new to blogs and definitely savored this blog site. Probably I’m likely to bookmark your blog . You certainly come with fantastic article content. Appreciate it for sharing your web site.

  5. I simply want to mention I am beginner to blogging and site-building and really enjoyed you’re web blog. Likely I’m want to bookmark your blog . You surely have amazing articles and reviews. Regards for sharing your web site.

  6. I simply want to tell you that I am very new to blogs and really enjoyed you’re web-site. Likely I’m want to bookmark your blog . You surely come with perfect stories. With thanks for sharing your web-site.

  7. I intended to compose you the very little word to be able to say thank you over again about the spectacular pointers you’ve shown here. It is quite remarkably open-handed with you to allow without restraint what a few people could possibly have marketed for an electronic book to help with making some bucks for their own end, most importantly considering the fact that you might well have tried it if you ever desired. Those things also worked to become fantastic way to realize that someone else have the identical eagerness much like mine to learn way more in terms of this condition. I think there are several more pleasant periods up front for individuals who take a look at your site.

  8. An fascinating discussion is value comment. I feel that it is best to write extra on this topic, it won’t be a taboo subject however typically individuals are not enough to talk on such topics. To the next. Cheers

  9. I really wanted to send a message so as to thank you for these nice points you are writing at this website. My extensive internet lookup has finally been honored with sensible suggestions to exchange with my guests. I would state that that we site visitors actually are really blessed to exist in a wonderful network with many brilliant professionals with very helpful solutions. I feel very much privileged to have encountered your entire web pages and look forward to really more brilliant times reading here. Thank you once again for everything.

  10. You can certainly see your expertise in the paintings you write. The sector hopes for even more passionate writers such as you who aren’t afraid to mention how they believe. All the time follow your heart. “What power has law where only money rules.” by Gaius Petronius.

  11. Good read, I just passed this onto a colleague who was doing just a little research on that. And he just bought me lunch since I found it for him smile So let me rephrase that: Thank you for lunch!

  12. It is in reality a great and useful piece of information. I am happy that you simply shared this useful info with us. Please keep us informed like this. Thank you for sharing.

  13. My husband and i have been quite fortunate Raymond managed to round up his basic research using the precious recommendations he received out of the weblog. It is now and again perplexing to simply be giving for free secrets and techniques that many some people have been trying to sell. And we also do know we have the writer to give thanks to because of that. The main illustrations you made, the straightforward website menu, the friendships your site help create – it’s got mostly amazing, and it is assisting our son and the family reckon that the subject matter is excellent, which is certainly really essential. Thanks for the whole thing!

  14. Good post. I realize something tougher on different blogs everyday. Most commonly it truly is stimulating you just read content material off their writers and use slightly something there. I’d choose to apply certain together with the content on my weblog regardless of whether you don’t mind. Natually I’ll give a link for your internet weblog. Several thanks sharing.

  15. Very interesting points you have noted , thanks for posting . “Never call an accountant a credit to his profession a good accountant is a debit to his profession.” by Charles J. C. Lyall.

  16. This really is very fascinating, You’re a quite specialist blogger. I’ve joined your rss feed and appear ahead to in search of a lot more of your amazing post. Also, I’ve shared your internet site in my social networks!

  17. Somebody essentially help gipelris to make seriously posts I would state. This is the first time I frequented your web page and thus far? I surprised with the research you made to make this particular publish amazing. Excellent job!

  18. Wow! This can be one particular of the most beneficial blogs We’ve ever arrive across on this subject. Actually Excellent. I am also a specialist in this topic so I can understand your hard work.

  19. Perfectly indited written content, regards for information. “The bravest thing you can do when you are not brave is to profess courage and act accordingly.” by Corra Harris.

  20. I’ve noticed that car insurance organizations know the cars which are at risk of accidents and various risks. Additionally, these men and women know what type of cars are susceptible to higher risk as well as the higher risk they have got the higher the premium price. Understanding the basic basics with car insurance will assist you to decide on the correct style of insurance policy that could take care of your needs in case you happen to be involved in any accident. Appreciate your sharing your concepts along with your blog.

  21. Extremely greatest man toasts, nicely toasts. is directed building your own by way with the wedding celebration as a result are supposed to try to be witty, amusing and consequently unusual as nicely as. best mans speech

  22. I’m glad for writing to let you know with the excellent experience my friend’s girl went through reading the weblog. She figured out several pieces, most notably how it’s like to have a great helping style to get a lot of a lot more smoothly completely grasp several specialized issues. You actually did much more than visitors’ expectations. Thank you for displaying those excellent, dependable, explanatory and in addition cool guidance on this subject to Lizeth.

  23. I got this web page from my friend who shared with me concerning this web page and now this time I am visiting this website and reading very informative posts at this place.|

  24. garcinia green coffee bean coleus forskolin dr oz dosage cvs green coffee bean extract 800mg acai berry tea k-cups mangosteen reactions with other medicines gnc hoodia chews psyllium dosing for benadryl chitosan immune response to bacteria guar gum jecfa food lipozene taken with other drugs glucomannan is an ancient fibers

  25. Thanks for all of the work on this site. Gloria take interest in setting aside time for research and it is easy to understand why. All of us know all regarding the compelling way you deliver advantageous solutions through this website and welcome contribution from some other people on that issue then my daughter is undoubtedly learning so much. Take advantage of the rest of the year. You have been conducting a wonderful job.


电子邮件地址不会被公开。 必填项已用*标注