|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-05-15 02:08 UTC] bousset1 at gmail dot com
Description: ------------ With more than 1024 sockets it produces a warning using stream_select(). It asks to recompile php with --enable-fd-setsize higher than the current value (which says is 1024). However, even after recompiling php with a higher value (2048, 4096, 65536, 9999999, etc) it gives the same error. My system (ubuntu 14.04) is tuned to allow a high number of opened files (I globally followed instructions described here https://rtcamp.com/tutorials/linux/increase-open-files-limit/ and here http://kb.odin.com/en/967). Then it seems not to be a problem from the system limits. Here attached a cli script that you can use to reproduce this problem (see the actual result section for details). It seems that I'm not the only one to encounter this problem : http://www.programering.com/a/MTO4cTMwATA.html If it can helps, here is my current configure line : ./configure '--enable-exif' '--enable-ftp' '--enable-sockets' '--enable-shmop' '--enable-mbstring' '--enable-mbregex' '--enable-bcmath' '--enable-calendar' '--with-gd' '--enable-gd-native-ttf' '--with-gettext' '--with-curl' '--disable-debug' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-mysql' '--with-pdo-mysql' '--disable-phpdbg' '--enable-opcache' '--with-zlib' '--with-bz2' '--with-iconv' '--with-mcrypt' '--enable-zip' '--with-tidy' '--with-mysqli' '--with-openssl' '--with-jpeg-dir=/usr/lib/x86_64-linux-gnu' '--enable-fd-setsize=65536' This issue (not a php bug) is very close to mine : https://bugs.php.net/bug.php?id=37025 however I changed the fd_setsize value in typesizes.h already. Test script: --------------- <?php $pid = getmypid(); $sockets = array(); $loopNbr = 1025; // This normally could go up to the compile --enable-fd-setsize value, but the limit will be anyway 1024, like if it has been hardcoded somewhere $sysLimit = min(posix_getrlimit()['soft openfiles'], posix_getrlimit()['hard openfiles']); $nbrInitialOpenedFiles = (int)exec("ls /proc/$pid/fd | wc -l"); echo "There is initially $nbrInitialOpenedFiles opened files".PHP_EOL."The sysLimit is $sysLimit".PHP_EOL."In some few seconds, we will try to open $loopNbr sockets".PHP_EOL; sleep(5); for ($i = 0; $i < $loopNbr; $i++) { echo $i > ($sysLimit - $nbrInitialOpenedFiles) ? 'Normal crash : openfiles system limitation. Edit /etc/security/limits.conf, increasing soft & hard values' . PHP_EOL : null; $s = stream_socket_client("127.0.0.1:80", $errno, $errstr, 30, STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT); if ($s) { $sockets[$i] = $s; echo 'Stream n°' . $i . ' opened' . PHP_EOL; echo(exec("lsof -i -a -p $pid") . PHP_EOL); } else {exit;} } echo ($loopNbr + $nbrInitialOpenedFiles) > 1024 ? 'Weird crash : ($loopNbr + $nbrInitialOpenedFiles) is > 1024' . PHP_EOL : 'Nbr of files descriptor <= 1024 <= sysLimit, then all should be ok' . PHP_EOL; $read = $sockets; stream_select($read, $w = null, $e = null, null, null); Expected result: ---------------- As long as the number of files descriptor is lower than --enable-fd-setsize and lower than the system limits, no error should occurs. Actual result: -------------- 1/ By default $loopNbr is set to 1025, that is > 1024. With this value, it produces the following error : "PHP 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 1027. --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." 2/ By changing $loopNbr to a value < 1024, such 1000, everything is ok. 3/ By changing your system limits (edit /etc/security/limits.conf then logout / login to apply), for exemple with a value of 512 it produces another error, which is a normal error. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 20:00:01 2025 UTC |
@[2016-11-08 10:45 UTC] - directly modifiying system headers may not be a good idea. Here's a simple patch (tested on php 7.2.14): --- main/php.h 2019-01-08 09:59:17.000000000 +0000 +++ main/php.h 2019-01-30 09:03:18.698899000 +0000 @@ -515,6 +515,11 @@ #endif +#undef __FD_SETSIZE +#define __FD_SETSIZE 32768 +#undef FD_SETSIZE +#define FD_SETSIZE 32768 + /* * Local variables: * tab-width: 4 ----------- Result: # php-7.2.14-009/bin/php -r "print_r(get_defined_constants(true));"|grep FD_SETSIZE [PHP_FD_SETSIZE] => 32768