在 Gentoo 上,spawn-fcgi/fast CGi php 崩溃,但日志中没有留下任何痕迹

在 Gentoo 上,spawn-fcgi/fast CGi php 崩溃,但日志中没有留下任何痕迹

我最近从 apache 迁移到 Nginx/fastcgi 解决方案,我在 Fedora 系统上运行它并且没有任何问题,但是,自从我将所有东西迁移到 Gentoo 后,Spawn-fCGI/fastcgi php 守护进程就死了,而且我在 /var/log/messages 上找不到任何错误报告,所以我不知道为什么会发生这种情况。

我发现 fastcgi 与 gentoo 上的 fedora 发行版有所不同,因为它有不同的配置文件和 init.d 启动脚本,有人能帮我让它更稳定吗?我收到的请求数与 fedora 上的请求数没有什么不同,所以我使用发行版附带的默认配置文件。大约几个小时后它就死机了……

非常感谢

答案1

这是我的文件的内容/etc/conf.d/php-cgi(它是原始 spawn-fcgi conf.d 文件的修改副本):

# The FCGI process can be made available through a filesystem socket or
# through a inet socket. One and only one of the two types must be choosen.
# Default is the inet socket.

# The filename specified by
# FCGI_SOCKET will be suffixed with a number for each child process, for
# example, fcgi.socket-1. 
# Leave empty to use an IP socket (default). See below. Enabling this, 
# disables the IP socket.
# 
FCGI_SOCKET=

# When using FCGI_PORT, connections will only be accepted from the following
# address. The default is 127.0.0.1. Use 0.0.0.0 to bind to all addresses.
#
FCGI_ADDRESS=127.0.0.1

# The port specified by FCGI_PORT is the port used
# by the first child process. If this is set to 1234 then subsequent child
# processes will use 1235, 1236, etc.
#
FCGI_PORT=2000

# The path to your FastCGI application. These sometimes carry the .fcgi
# extension but not always. For PHP, you should usually point this to
# /usr/bin/php-cgi.
#
FCGI_PROGRAM=/usr/bin/php-cgi
#FCGI_PROGRAM=/usr/bin/spawn-fcgi

# The number of child processes to spawn. The default is 1.
#
FCGI_CHILDREN=1

# If you want to run your application inside a chroot then specify the
# directory here. Leave this blank otherwise.
#
FCGI_CHROOT=

# If you want to run your application from a specific directiory specify
# it here. Leave this blank otherwise.
#
FCGI_CHDIR=

# The user and group to run your application as. If you do not specify these,
# the application will be run as root:root.
#
FCGI_USER=nginx
FCGI_GROUP=nginx

# Additional options you might want to pass to spawn-fcgi
#
#FCGI_EXTRA_OPTIONS=

# If your application requires additional environment variables, you may
# specify them here. See PHP example below.
#
#ALLOWED_ENV="PATH"

# PHP ONLY :: These two options are specific to PHP. The first is the number
# of child processes to spawn. The second is the number of requests to be
# served by a single PHP process before it is restarted.
#
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500
#
# For this to work you would set
ALLOWED_ENV="PATH PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS"

然后要创建 init.d 文件,只需使用 conf.d 文件的名称(在我的情况下为 php-cgi)创建指向原始 spawn-fcgi init.d 文件的符号链接:

% sudo ln -s /etc/init.d/spawn-fcgi /etc/init.d/php-cgi

然后你可以这样启动它:

% /etc/init.d/php-cgi start

并将其添加到默认启动级别

% rc-update add php-cgi default

你唯一的自由度就是调整这两个值:

PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500

更多的子进程可以同时处理更多的请求,但会消耗更多的内存。
根据您的硬件配置,调整这两个设置。

答案2

这里遇到了完全相同的问题...通过以交互模式运行 spawn-fcgi(以便它不会分叉)并将其包裹在无限的 while 循环中(以便它重新启动)解决了该问题。

答案3

我遇到了同样的问题...

我遇到了两种解决方案:

  • cron fastcgi 重启:“0 * * * * /etc/init.d/fastcgi restart”。虽然丑陋,但确实有效
  • 问题似乎出在 php-cgi 进程长时间运行后变得不稳定。可以通过环境变量“export PHP_FCGI_MAX_REQUESTS=500”强制 php-cgi 在达到最大请求数后更新进程来解决此问题

相关内容