PHP 在高负载下苦苦挣扎 - “无法准备 stderr 管道:打开的文件太多(24)”

PHP 在高负载下苦苦挣扎 - “无法准备 stderr 管道:打开的文件太多(24)”

我们正在运行带有以下软件的服务器: - Plesk 12.5 - Apache 2.4.6 - nginx 1.11.1 - PHP 5.6 - Centos 6 - MySQL (MariaDB) 5.5.60

我们注意到,当我们的服务器负载过重时,PHP 会反复出现此错误。我们在高峰实时流量期间以及在服务器克隆上进行负载测试时都遇到过这种情况。

在 /var/log/plesk-php56-fpm/error.log 中:

[07-May-2020 05:45:20] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[07-May-2020 05:45:21] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[07-May-2020 05:45:21] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[07-May-2020 05:45:21] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[07-May-2020 05:45:21] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[07-May-2020 05:45:21] ERROR: failed to prepare the stderr pipe: Too many open files (24)

当我们看到这些错误时,我们会收到很多 504 网关超时。

我们可以看到 PHP 进程的文件限制为 1024,这似乎太低了(我们已经为 MySQL/Apache/Nginx 增加了它,但不知道如何为 PHP 增加它):

在 /proc/{php_process}/limits 中:

Max open files 1024 4096 files

我们不知道该如何增加这个数字。

# ulimit -n
65535

在 /etc/security/limits.conf 中:

* soft nofile 65535
* hard nofile 65535

在 /proc/sys/fs/file-max 中:

250000

在 /etc/sysctl.conf 中:

fs.file-max = 250000

完成这些更改后,我们重新启动了服务器。

关于增加 PHP 的最大打开文件数有什么建议吗?

答案1

rlimit_files文件中php-fpm.conf需要调整的参数为:

rlimit_files = 4096

路径php-fpm.conf应该是这样的/etc/php/5.6/fpm/php-fpm.conf

相关内容