mod_fcgid出现500错误的解决
MT上的php5是用mod_fcgid方式运行的,但运行一段时间之后,有时候会莫名其妙的出现500错误,也看不出是哪个php程序错误,不过html文件倒能正常解析,查看用户的$HOME/statistics/logs/error_log
文件,会发现大量这样的内容:
[Fri Aug 10 01:00:43 2007] [error] [client 202.108.23.76] Premature end of scrip
t headers: index.php
[Fri Aug 10 01:01:20 2007] [error] [client 60.191.82.228] Premature end of scrip
t headers: index.php
而在系统的log文件/var/log/apache/error_log
中,是这样的错误:
[Fri Aug 10 01:03:05 2007] [notice] mod_fcgid: process /var/www/vhosts/fwolf.com
/httpdocs/blog/index.php(21666) exit(communication error), terminated by calling
exit(), return code: 120
G到一些资料,第一类错误是脚本执行被中断,没有返回完整的http header;第二类错误是cgi程序的执行被强行中止。根本原因是fastcgi会自动kill掉一些发呆的、长时间没有响应的进程(要不它比较快,比较省内存啊),但是fastcgi的默认idle时间设置过于苛刻(官方文档中每个选项都有默认的时间值),所以有些处理比较慢、需要调用外部资源的程序就有可能被误杀,所以先略微调整一下,继续观察:
<IfModule mod_fcgid.c>
IdleTimeout 600
ProcessLifeTime 3600
MaxProcessCount 8
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 3
IPCConnectTimeout 30
IPCCommTimeout 600
#MaxRequestsPerProcess 500
</IfModule>
- IdleTimeout 发呆时限
- ProcessLifeTime 一个进程的最长生命周期,过期之后无条件kill
- MaxProcessCount 最大进程个数
- DefaultMinClassProcessCount 每个程序启动的最小进程个数
- DefaultMaxClassProcessCount 每个程序启动的最大进程个数
- IPCConnectTimeout 程序响应超时时间
- IPCCommTimeout 与程序通讯的最长时间,上面的错误有可能就是这个值设置过小造成的
- MaxRequestsPerProcess 每个进程最多完成处理个数,达成后自杀,因为PHP最多只处理500次请求。不过这个是mod_fcgid 1.11版本添加的,我们主机上暂时不支持。
上述选项的确切作用我也不是十分清楚,先用着这个设置,再根据情况调整。
参考:
- The mod_fcgid Home Page
- Ruby on Rails > fcgid -> errors
- Rails on Fedora + Plesk Fiasco
- [typo] Error with large number of flickr images
- Secure PHP environments with PHP, suexec and FastCGI (mod fcgid) (en)
- Problem with PHP5 as fcgid
- mod_fcgid instead of mod_fastcgi – Images don’t load?!?!
- Hou, senseless timeout setting of fcgid
- HDD and mod_fcgid Frustration
- Debian mod_fastcgi Notes
- Watch for huge requests on default FCGI
- 全文:http://www.fwolf.com/blog/post/349