首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux php-cgi 100%过程处理

2012-08-11 
linux php-cgi 100%进程处理 有时候,运行 Nginx、PHP-CGI(php-fpm) Web服务的 Linux 服务器,突然系统负载上

linux php-cgi 100%进程处理
 有时候,运行 Nginx、PHP-CGI(php-fpm) Web服务的 Linux 服务器,突然系统负载上升,使用 top 命令查看,很多 php-cgi 进程 CPU 使用率接近100%。后来,我通过跟踪发现,这类情况的出现,跟 PHP 的 file_get_contents() 函数有着密切的关系。

  大、中型网站中,基于 HTTP 协议的 API 接口调用,是家常便饭。PHP 程序员们喜欢使用简单便捷的 file_get_contents("http://example.com/") 函数,来获取一个 URL 的返回内容,但是,如果 http://example.com/ 这个网站响应缓慢,file_get_contents() 就会一直卡在那儿,不会超时。

  我们知道,在 php.ini 中,有一个参数 max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm) 中,该参数不会起效。真正能够控制 PHP 脚本最大执行时间的是 php-fpm.conf 配置文件中的以下参数:
view plainprint?

select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)select(7, [6], [6], [], {15, 0})        = 1 (out [6], left {15, 0})poll([{fd=6, events=POLLIN}], 1, 0)     = 0 (Timeout)

  那么,就可以确定是 file_get_contents() 导致的问题了。

热点排行