不能增加PHP中打开的最大文件数


Can't incrase maximum opened files in PHP

我有一个网站运行php-fpm与nginx在ubuntu与套接字系统,当网站达到约1000个用户我的套接字抛出一个错误并关闭我不确定是系统问题还是PHP问题。

Symfony'Component'Debug'Exception' contextrorexception]警告:stream_select():你必须用更大的FD_SETSIZE值重新编译PHP。它被设置为1024,但是您的描述符的编号至少高达1024。——enable-fd-setsize=2048是推荐的,但你可能想把它设置为等于你的系统支持的最大打开文件数,以避免在以后的日期再次看到这个错误。

我用以下配置重新编译了PHP -

。/configure '——enable-fpm '——enable-pdo '——with-pdo-mysql '——enable-sockets '——enable-exif '——enable-soap '——enable-ftp '——enable-wddx '——enable-pcntl '——enable-soap '——enable-bcmath '——enable-mbstring '——enable-dba '——enable-gd-native-ttf '——enable-zip '——enable-calendar '——使用mysql '——with-mysqli '——with-pdo-sqlite '——with-iconv '——with-zlib '——with-bz2 '——with-gettext '——with-xmlrpc '——使用openssl '——with-mhash '——with-mcrypt '——使用xsl '——使用curl '——with-pcre-regex '——与gd '——with-freetype-dir =/usr '——with-jpeg-dir =/usr '——with-png-dir =/usr '——与ldap '——梨'——www - data ' with-fpm-user =——www - data ' with-fpm-group =——with-config-file-path =/etc/php/'——with-config-file-scan-dir =/etc/php/conf。d/'——with-libdir = lib/x86_64-linux-gnu '——enable-fd-setsize = 131072

并在bits/types .h、linux/posix_types.h 中设置相同的限制

ulimit -Sn return 128000

我还编辑了/etc/security/limits.conf,如下-

www-data soft nofile 128000

www-data hard nofile 128000

  • soft nproc 128000

  • hard nproc 128000

  • soft nofile 128000

  • 硬文件128000

** EDIT 1:**

刚刚发现了一种新的方法,可以在运行时检查特定进程的限制Cat/proc/1719/limits(1719是nginx进程之一)我得到最大打开文件软限制1024,硬限制4096,我相信这就是导致问题的原因,虽然我找不到如何提高它..

** EDIT 2:**

通过在运行脚本中添加ulimit -n 512000修复了这个软限制(在nginx和php-fpm中都添加了这个软限制),但仍然会出现相同的错误。

这个问题是在一个已知的PHP错误中,打开文件的限制是从linux系统中获取的,所以如果在重新编译时是1024,它将忽略——enable-fd-setsize=131072。你必须在更改linux系统设置后进行编译。祝你好运!