nginx – 我的php-fpm配置出了什么问题?

我有一个64位服务器,但只有256MB的RAM.所以,我用fast-cgi移动到nginx服务器连接到PHP.我运行PHP 5.3.6.

问题是,每当我尝试访问任何PHP页面的两三天后,我就会收到服务器内部错误.唯一的方法是手动重启php-fpm.这意味着我应该设置一些错误的参数,导致它窒息.下面我列出了相关的配置.

/etc/php-fpm.conf: –

include=/etc/php-fpm.d/*.conf
log_level = error
;emergency_restart_threshold = 0
;emergency_restart_interval = 0
;process_control_timeout = 0

/etc/php-fpm.d/www.conf: –

[www]
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.max_requests = 500

/etc/nginx/php.conf: –

location ~ \.php {
        fastcgi_param  QUERY_STRING       $query_string;
        fastcgi_param  REQUEST_METHOD     $request_method;
        fastcgi_param  CONTENT_TYPE       $content_type;
        fastcgi_param  CONTENT_LENGTH     $content_length;

        fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  REQUEST_URI        $request_uri;
        fastcgi_param  DOCUMENT_URI       $document_uri;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        fastcgi_param  SERVER_PROTOCOL    $server_protocol;

        fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
        fastcgi_param  SERVER_SOFTWARE    nginx;

        fastcgi_param  REMOTE_ADDR        $remote_addr;
        fastcgi_param  REMOTE_PORT        $remote_port;
        fastcgi_param  SERVER_ADDR        $server_addr;
        fastcgi_param  SERVER_PORT        $server_port;
        fastcgi_param  SERVER_NAME        $server_name;

        fastcgi_pass unix:---some-location---;
}

更新1

我有四个运行的nginx进程.平均每个php-fpm进程占用35MB RAM(虚拟内存大小为320MB).我还运行了一个MySql进程.

更新2

我忘记粘贴日志了.

php-fpm错误日志: –

WARNING: [pool www] seems busy (you may need to increase start_servers, or min/max_spare_servers), spawning 8 children, there are 1 idle, and 7 total children
WARNING: [pool www] server reached max_children setting (10), consider raising it
NOTICE: Terminating ...

php-fpm www.error日志: –

PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/webadmin/blog.applegrew.com/html/wordpress/wp-content/plugins/jetpack/class.jetpack-signature.php on line 137
PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/webadmin/blog.applegrew.com/html/wordpress/wp-content/plugins/jetpack/class.jetpack-signature.php on line 137
PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/webadmin/blog.applegrew.com/html/wordpress/wp-content/plugins/jetpack/class.jetpack-signature.php on line 137
一个副手建议是降低你的设定值 – 可能会减少一半.

你有:pm.max_children = 10
如果你说35MB / process = 350MB;在一个256MB的盒子上,这意味着要么进行大量的交换,要么你的内存耗尽 – 两者都不好.

我要说其他进程至少需要100MB,甚至可以保证150MB,然后将这个数字除以35MB以获得你的max_children.保持所有其他数字符合:

pm = dynamic
pm.max_children = 4
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 2
pm.max_requests = 500

停止PHP-FPM并自由运行以了解您的可用内存 – 除以35MB以获得您的max_children.

根据MySQL占用的内存量,您可能必须将max_children删除为3.

我发现PHP-FPM进程共享大量内存,做一个快速实验来确定实际使用了多少.停止PHP-FPM并免费运行.启动PHP-FPM访问一些常见页面(因为内存增加,这取决于加载的页面),并检查使用的总内存,再次使用自由 – 除差异进程数.它不是一个完美的系统,但我发现它相当准确(有时顶部的数据列也不错).

翻译自:https://serverfault.com/questions/295766/what-is-wrong-in-my-php-fpm-configuration

转载注明原文:nginx – 我的php-fpm配置出了什么问题?