问题描述
在各种共享主机上,基于PHP/MySQL的网站上一直出现随机500 Internal Server
错误.我在共享Linux服务器上通过CGI/FastCGI使用PHP 5.2.17.当我查看日志时,会看到以下内容:
I've been having random 500 Internal Server
errors on my PHP / MySQL based sites on various shared hosts. I'm using PHP 5.2.17 through CGI/FastCGI on a shared Linux server. When I look in the logs, I see this:
[error] [client 75.71.176.224] (104)Connection reset by peer: FastCGI: comm with server "/dev/shm/blackmou-php.fcgi" aborted: read failed, referer: ...
[error] [client 75.71.176.224] FastCGI: incomplete headers (0 bytes) received from server "/dev/shm/blackmou-php.fcgi", referer: ...
[error] [client 75.71.176.224] (104)Connection reset by peer: FastCGI: comm with server "/dev/shm/blackmou-php.fcgi" aborted: read failed, referer: ...
[error] [client 75.71.176.224] FastCGI: incomplete headers (0 bytes) received from server "/dev/shm/blackmou-php.fcgi", referer: ...
有人知道如何解决这个问题吗?
Anyone knows how to resolve this?
推荐答案
此问题通常不仅与主机有关,而且还与开发人员相关,具体取决于配置.但是,某些主机对FastCGI的要求非常严格,并且会限制您的功能.除非您特别需要在应用程序中使用FastCGI,否则通常无需使用FastCGI即可运行,而只需使用mod_php即可.
This issue is generally not just Host specific, it is developer related as well, depending on the configuration.However some hosts are rather strict with FastCGI and will limit your capabilities.It is generally easier to run without using FastCGI and just use mod_php unless you have specific need to use FastCGI in your application.
我们需要查看您的fcgi包装器(在/dev/shm/blackmou-php.fcgi中是什么)或.htaccess来生成FastCGI,以便更好地为您提供帮助,而又不知道哪个文件以及这些文件上的代码是问题所在发生.您的主机还使用Apache,LightHttpd或Nginx(或组合)吗?当时我强烈建议您更新为使用PHP 5.3.9 +
We would need to see your fcgi wrapper (what's in /dev/shm/blackmou-php.fcgi) or .htaccess for FastCGI spawning, to better assist you without knowing which files and the code that is on those files the issue occurs with.Also do your hosts use Apache, LightHttpd, or Nginx (or combination)?At that point I strongly suggest updating to use PHP 5.3.9+
由于这可能是由许多问题引起的,因此FastCGI有效地防止您的站点/脚本遭到拒绝服务攻击或由于内存泄漏等导致的崩溃.(例如:尝试通过丢弃和限制请求数量来处理80,000个连接,或者通过超时和终止进程陷入无限循环)
As this can be caused by any number of issues, FastCGI effectively prevents your site/scripts from being attacked by a Denial of Service or crashing due to memory leaks, etc.(EG: trying to handle 80,000 connections simply by dropping and limiting the number of requests or getting stuck in an endless loop by timing out and terminating the process)
此错误通常通常是由idle_timeout(默认为30秒)或最大子进程限制引起的.也可能是因为有人启动了长时间运行的脚本并在脚本完成之前关闭了浏览器/连接.
This error in particular is generally caused by an idle_timeout (30 seconds by default) or max children processes limit.It can also be caused by someone starting a long running script and closing their browser/connection before the script completes.
FastCGI启动其进程包装器,执行命令,在完成该过程之前超时,连接被对等方重置.
FastCGI launches its process wrapper, executes a command, times out prior to completing the process, connection seen as reset by peer.
另一个示例是达到了最大子级数(maxProcesses)(例如:很多站点以2或4为例,实际上,根据平均流量,您可能需要20或50)如果当前所有子代都处于活动状态,并且进行了其他请求/连接,则子代仅限于maxProcesses,FastCGI将不会共享这些子代,因此FastCGI必须首先终止进程并启动新的子进程,或者删除请求,具体取决于您的配置.
Another example is that max children (maxProcesses) is reached (EG: a lot of sites show 2 or 4 as an example when in reality you may need 20 or 50 depending on average traffic)If all children are currently active and an additional request/connection is made, the children is limited to maxProcesses, to which FastCGI will not share the active children, so it must first either terminate the process and start a new child process, or drop the request, depending on your configurations.
以下是有关设置的更多信息:
Here is some more information on the settings:
http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
http://www.fastcgi.com/drupal/node/10
包装示例
PHP_FCGI_CHILDREN=0 #no limit
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS
更新
要补充一点,这也可能是由于php内存限制
To add on to this, this can also be caused by php memory limit
如果上述方法不能解决您的问题,请更新php.ini以增加 memory_limit
If the above doesn't resolve your issue, update your php.ini to increase memory_limit
这篇关于随机PHP FastCGI/通过对等项/不完整的标头重置连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!