dqdjfb2325 2015-10-25 21:33
浏览 76

无法在PHP中删除最大打开的文件

I have a website running php-fpm with nginx on ubuntu with socket system, when the site reach about 1000 users my socket throws an error and shuts down I'm not sure if its system problem or 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.

I have recompiled PHP with the following configurations -

./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

and set the same limit in bits/typesizes.h, linux/posix_types.h

ulimit -Sn return 128000

I have also edited the /etc/security/limits.conf with the following -

www-data soft nofile 128000

www-data hard nofile 128000

  • soft nproc 128000

  • hard nproc 128000

  • soft nofile 128000

  • hard nofile 128000

** EDIT 1 :**

Just found out about a new way to check limit for specific process when I run cat /proc/1719/limits (1719 is one of the nginx process) I get max open files soft limit 1024, hard limit 4096, I believe that’s what cause the issue, though I can't find how to raise it up..

** EDIT 2 :**

fixed that soft limit by adding ulimit -n 512000 to the run script (added it to both nginx and php-fpm), but still crush with same error.

  • 写回答

1条回答 默认 最新

  • douzhang1955 2015-10-27 13:47
    关注

    The problem was in a known PHP bug, the limit of opened files is taken from the linux system so if its 1024 while re-compiling it will ignore the --enable-fd-setsize=131072. you have to compile AFTER you change the linux system settings. Good luck :)

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度