简体   繁体   English

php5-fpm摇篮

[英]php5-fpm craches

I have a webserver (nginx) running debian and php5-fpm randomly seems to crach, it replys with 504 bad gateway if i call php files. 我有一个运行debian和php5-fpm的网络服务器(nginx)似乎随机播放,如果我调用php文件,它将以504错误的网关答复。

when it is in a crashed state and i do sudo /etc/init.d/php5-fpm it says that it is running, but it will still it gives 504 bad gateway until i do sudo /etc/init.d/php5-fpm 当它处于崩溃状态并且我执行sudo /etc/init.d/php5-fpm时,它说它正在运行,但是在我执行sudo /etc/init.d/php5-之前,它仍然会提供504错误的网关。 fpm

I'm thinking that it has maybe to do with one of my php files which is in a infinity loop until a certain event occurs (change in mysql database) or until it will be time-outed. 我在想这可能与我的一个php文件有关,该文件处于无限循环中,直到发生某个事件(mysql数据库中的更改)或直到它超时为止。 I don't know if generally that is a good thing or if i should make the loop quit itself before a timeout occurs. 我不知道这通常是否是件好事,还是我应该在发生超时之前退出循环。

Thanks in advice! 感谢您的建议!

First look at the nginx error.log for the actual error. 首先查看nginx error.log中的实际错误。 I don't think PHP crashed, just your loop is using all available php-fpm processes, so there is none free to serve your next request from nginx. 我不认为PHP会崩溃,只是您的循环正在使用所有可用的php-fpm进程,因此没有免费服务于nginx的下一个请求。 That should produce Timeout error in the logs (nginx will wait for some time for available php-fpm process). 那应该在日志中产生超时错误(nginx将等待一段时间以等待可用的php-fpm进程)。

Regarding your second question. 关于第二个问题。 You should not use infinite loops for this. 您不应该为此使用无限循环。 And if you do, insert sleep() command inside the loop - otherwise you will overload your CPU with that loop and also database with queries. 并且如果这样做,请在循环内插入sleep()命令-否则,您将使该循环的CPU以及查询数据库过载。

Also I guess it is enough to have one PHP process in that loop waiting for a event. 我也猜想在那个循环中有一个PHP进程等待一个事件就足够了。 In that case use some type of semaphore (file or info in db) to let other processes know that one is already waiting for that event. 在这种情况下,请使用某种类型的信号量(db中的文件或信息)让其他进程知道已经在等待该事件。 Otherwise you will always eat up all available PHP processes. 否则,您将永远吃光所有可用的PHP进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM