关于PHP-FPM的reload

由于最近在看接口监控的时候发现有一些502的情况,所以打算排查下原因。看了下nginx及php-fpm日志后偶然发现报502的时间节点跟fpm重启正好吻合。确认了下这个重启只是reload的操作而非restart的操作。什么?reload不是平滑启动吗?怎么会导致这样的问题出现呢?上网查了下资料后发现也有很多人遇到过这种情况。

接下来重现下这种情况。写几行代码来实际模拟下:

sleep(10);
echo "test";

然后在浏览器中访问一下,同时执行fpm reload的操作。可以看到执行完reload后页面立马就502了。
实际上通过process_control_timeout参数可以实现我们的目标。可惜这个参数缺省是 0,也就是不生效,这里把它设置成为2s。然后再重复一次上面的操作后发现页面可以正常输出test。同时会发现页面并不会等待10s后打印test。当我们 reload 的时候,sleep 立刻就结束了,这是因为 sleep 收到 reload 发出的信号后直接返回了。

process_control_timeout参数参考官网文档的解释:设置子进程接受主进程复用信号的超时时间。可用单位:s(秒),m(分),h(小时)或者 d(天)。默认单位:s(秒)。默认值:0(关闭)。
即reload的时候,如果有正在执行的请求进程便会等待该进程设置的时长。而其他进程直接就结束掉。等待正在执行的进程执行完或者是超过了设置的时间后fpm的master进程才开始生成新的fpm worker进程。

结论
默认情况下,PHP-FPM 无法保证平滑的执行 reload 操作,必须设置一个合理的 process_control_timeout 才行,同时需要注意的是其值不能设置的过大,否则系统可能出现严重的请求堵塞问题。

62 Responses

  1. Superb blog you have here but I was curious if you knew of
    any user discussion forums that cover the
    same topics talked about in this article? I’d really like to be a part of
    online community where I can get feed-back from other knowledgeable people that share the same interest.
    If you have any suggestions, please let me know. Cheers!

  2. Hi there very nice site!! Man .. Excellent .. Amazing ..
    I will bookmark your site and take the feeds additionally?
    I’m glad to search out numerous useful information here within the submit, we’d like work out more techniques on this
    regard, thanks for sharing. . . . . .

  3. Just desire to say your article is as astonishing. The clearness in your post is just cool and i can assume you are an expert on this subject.
    Fine with your permission let me to grab your feed to
    keep updated with forthcoming post. Thanks a million and please continue the
    gratifying work.

  4. You are so awesome! I do not think I’ve read a single thing like this before.
    So good to discover another person with some genuine
    thoughts on this subject. Seriously.. many thanks for starting this up.
    This site is one thing that is required on the web, someone with a bit
    of originality!

  5. I love your blog.. very nice colors & theme.
    Did you make this website yourself or did you hire someone to do it for you?
    Plz reply as I’m looking to construct my own blog and would like to know where u
    got this from. many thanks

  6. I got this site from my pal who informed me concerning this web
    page and now this time I am visiting this web site and reading very informative content at this time.

  7. You have made some really good points there.
    I looked on the net for additional information about the issue and found most individuals will go along
    with your views on this site.

  8. If you would like to obtain a good deal from this article then you have to apply such techniques to your won website.

  9. I’ve been surfing online more than 3 hours lately, yet I by no means found any interesting article like
    yours. It’s beautiful price enough for me. In my opinion, if all website owners
    and bloggers made good content material as you probably did,
    the net might be a lot more helpful than ever before.

  10. Howdy this is somewhat of off topic but I was wanting to
    know if blogs use WYSIWYG editors or if you have
    to manually code with HTML. I’m starting a blog soon but have
    no coding skills so I wanted to get advice from someone with
    experience. Any help would be greatly appreciated!

  11. I’m really loving the theme/design of your weblog.
    Do you ever run into any browser compatibility issues?

    A handful of my blog audience have complained about
    my site not working correctly in Explorer but looks great in Chrome.
    Do you have any tips to help fix this issue?

  12. Write more, thats all I have to say. Literally, it
    seems as though you relied on the video to make your
    point. You definitely know what youre talking
    about, why waste your intelligence on just posting videos to your site when you could be giving us something informative to read?

  13. I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored material stylish.
    nonetheless, you command get got an shakiness over that you
    wish be delivering the following. unwell unquestionably come further formerly again since exactly the
    same nearly a lot often inside case you shield this hike.

  14. It is in reality a nice and helpful piece of information. I’m happy that you shared
    this helpful information with us. Please stay us up to date like this.
    Thanks for sharing.

  15. Hello there! I know this is kind of off topic but I was wondering which blog platform are you using
    for this website? I’m getting fed up of WordPress because I’ve had issues with hackers
    and I’m looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform.

  16. of course like your web site however you need to take
    a look at the spelling on quite a few of your posts. A number of them
    are rife with spelling issues and I in finding it very troublesome to tell the truth however I’ll
    definitely come back again.

  17. This is really interesting, You’re a very skilled blogger.

    I’ve joined your rss feed and look forward to seeking more of your wonderful post.
    Also, I have shared your website in my social
    networks!

  18. I think this is one of the most vital info for me. And i
    am glad reading your article. But want to remark on few general things,
    The site style is perfect, the articles is really great :
    D. Good job, cheers

  19. Excellent blog! Do you have any hints for aspiring writers?
    I’m planning to start my own website soon but I’m a little
    lost on everything. Would you recommend starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely
    overwhelmed .. Any ideas? Bless you!

  20. Hi! This is my first comment here so I just wanted
    to give a quick shout out and tell you I really enjoy reading your blog posts.
    Can you recommend any other blogs/websites/forums that
    deal with the same subjects? Many thanks!

  21. Undeniably imagine that which you said. Your favorite reason seemed to be on the net the easiest thing to take note of.
    I say to you, I certainly get irked at the same time as
    other people consider worries that they plainly don’t know about.
    You managed to hit the nail upon the top and outlined
    out the entire thing with no need side-effects , other folks could take a signal.
    Will probably be again to get more. Thank you

  22. I’m not certain where you’re getting your information, but good topic.
    I must spend some time studying more or working out
    more. Thanks for magnificent information I was on the
    lookout for this information for my mission.

  23. Greetings! This is my first visit to your blog! We are a team of volunteers and starting a new
    project in a community in the same niche. Your blog provided us
    valuable information to work on. You have done
    a outstanding job!

  24. Please let me know if you’re looking for a article author for your blog.

    You have some really good articles and I think I would be a good
    asset. If you ever want to take some of the load off, I’d absolutely love to write
    some material for your blog in exchange for a link back
    to mine. Please send me an e-mail if interested.
    Thank you!

  25. I’m impressed, I must say. Rarely do I encounter a blog that’s both equally educative and entertaining, and let me
    tell you, you’ve hit the nail on the head. The issue is something that too few folks
    are speaking intelligently about. I’m very happy
    I stumbled across this during my search for something relating to this.

  26. Oh my goodness! Awesome article dude! Thanks, However I am going through
    difficulties with your RSS. I don’t know why
    I am unable to join it. Is there anybody getting identical RSS problems?
    Anyone that knows the solution will you kindly respond?
    Thanx!!

  27. With havin so much content and articles do you ever run into any issues of plagorism or
    copyright violation? My website has a lot of completely unique content
    I’ve either written myself or outsourced but it seems a lot
    of it is popping it up all over the web without my permission. Do you know any
    methods to help prevent content from being stolen? I’d certainly appreciate it.

  28. I am really inspired together with your writing talents as
    neatly as with the format for your blog.
    Is this a paid topic or did you customize it yourself?
    Anyway keep up the nice high quality writing, it is
    uncommon to see a great weblog like this one these days..

  29. Your style is really unique in comparison to other folks
    I’ve read stuff from. Many thanks for posting when you have the opportunity,
    Guess I will just bookmark this web site.

  30. Hey there! I understand this is sort of off-topic however
    I needed to ask. Does running a well-established website like yours require a large amount of work?
    I am brand new to writing a blog however I do
    write in my diary on a daily basis. I’d like to start a blog so I can share my experience and feelings online.
    Please let me know if you have any kind of ideas or tips for brand new aspiring
    bloggers. Appreciate it!

  31. Hi there, I believe your blog could be having browser compatibility problems.
    Whenever I take a look at your blog in Safari, it looks fine but when opening in Internet Explorer,
    it has some overlapping issues. I simply wanted to provide
    you with a quick heads up! Besides that, fantastic website!

  32. I have read some good stuff here. Definitely price bookmarking for
    revisiting. I surprise how so much attempt you set to create
    such a wonderful informative website.

  33. We stumbled over here from a different website and thought I may as well check things out.
    I like what I see so now i am following you. Look forward to
    checking out your web page repeatedly.

发表评论

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