php - 无法增加 PHP 中打开的最大文件数

标签 php linux sockets nginx

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

Symfony\Component\Debug\Exception\ContextErrorException] Warning: stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE. It is set to 1024, but you have descriptors numbered at least as high as 1024. --enable-fd-setsize=2048 is recommended, but you may want to set it to equal the maximum number of open files supported by your system, in order to avoid seeing this error again at a later date.

我已经使用以下配置重新编译了 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 \ --with-mysql \ --with-mysqli \ --with-pdo-sqlite \ --with-iconv \ --with-zlib \ --with-bz2 \ --with-gettext \ --with-xmlrpc \ --with-openssl \ --with-mhash \ --with-mcrypt \ --with-xsl \ --with-curl \ --with-pcre-regex \ --with-gd \ --with-freetype-dir=/usr \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --with-ldap \ --with-pear \ --with-fpm-user=www-data \ --with-fpm-group=www-data \ --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/typesizes.h, linux/posix_types.h中设置相同的限制

ulimit -Sn 返回 128000

我还使用以下内容编辑了/etc/security/limits.conf -

www-data soft nofile 128000

www-data hard nofile 128000

  • soft nproc 128000

  • hard nproc 128000

  • soft nofile 128000

  • hard nofile 128000

** 编辑 1:**

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

** 编辑 2:**

通过将 ulimit -n 512000 添加到运行脚本(将其添加到 nginx 和 php-fpm)来修复该软限制,但仍然会出现相同的错误。

最佳答案

问题出在一个已知的 PHP 错误中,打开文件的限制取自 linux 系统,因此如果它的 1024 在重新编译时将忽略 --enable-fd-setsize=131072。您必须在更改 linux 系统设置后进行编译。祝你好运 :)

关于php - 无法增加 PHP 中打开的最大文件数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33335330/

相关文章:

javascript - 使用 jQuery AJAX 调用将数据传递到函数中

java - 为什么java.nio.SocketChannel不发送数据(Jdiameter)?

linux - 如何将基于日期的 CSV 文件转换为电子表格?

linux - 我想通过使用 bash 脚本获得 rm 命令过滤器的提示

c++ - 检查套接字关闭

flash - Adobe 套接字策略文件服务器问题

javascript - 当 url 为 "example.php/1/2"时,CSS 不适用

php - 我可以在 Laravel 的路由组中对多个域进行分组吗?

php - 从 2 个变量获取总小时数

c - 查找位数组中的第一个零