From: jed at jed dot bz Operating system: Windows XP SP2 PHP version: 5.0.2 PHP Bug Type: Sockets related Bug description: socket_select() fails when managing large numbers of sockets
Description: ------------ Posted to php.general. Posted here on behalf of original bug discoverer, as I wrote a large test case for it. PHP 5.0.2 CLI Windows XP SP 2 with DEP excepted for PHP-CLI (DEP *was* a problem early, but I excepted it for php.exe) socket_select() will fail when managing a large number of sockets. The sockets extension itself can manage a bunch, but when socket_select() is attempted with a 'read' array larger than exactly 64 sockets, it prints out the following message and dies: Warning: socket_select(): unable to select [0]: An operation was attempted on something that is not a socket. PHP's problem? My problem? A print_r of the array before feeding it to socket_select shows this: Array ( [1] => Resource id #4 [2] => Resource id #5 [3] => Resource id #6 (...) [64] => Resource id #67 [65] => Resource id #68 ) Valid resources, I'd assume. Zero-basing the array causes the same problem. If there are more than exactly 64 sockets in the array fed to socket_select for the read parameter socket_select() will fail. Due to lack of time I'll only submit the test case for read, but write and except might be prone to the same problem. Let's tackle one at a time. Latest CVS was unusable as the sockets extension currently doesn't link correctly (numerous PHP startup warnings were encountered when starting php just for php -v)... The snaps I used to obtain this result were 5.0.x-dev 200411201730 ("5.0.3-dev") 5.1.x-dev 200411201930 Might have been misconfiguration on my end, because 5.0.x popped up a box reporting a mismatch between extensions even after I changed extension_dir to the snapshot package's extensions. Reproduce code: --------------- The Server http://labs.jed.bz/HCJ/server.php.txt The Load Client http://labs.jed.bz/HCJ/load.php.txt When executing, make sure $max_connections in the server is exactly equal to $connections in the load tester (or, if you prefer, make it one under, and telnet in to the server to make the last one). Expected result: ---------------- ... connecting #65 of 65 ... ok waiting for spew Array ( ... ) spew! done! Actual result: -------------- [63] => Resource id #67 [64] => Resource id #68 ) Warning: socket_select(): unable to select [0]: An operation was attempted on something that is not a socket. in F:\Projects\HCJ\load.php on line 39 spew! done! ---------------- This appeared in my debugger output while I was messing with getting a backtrace (possible in VS?). Interest you? First-chance exception at 0x7c81eb33 in php.exe: 0x000006A6: The binding handle is invalid. ---------------- I can't recompile with debug symbols at this point, I'm unfortunately pressed for time. Perhaps someone can run it through VS and see what comes up. -- Edit bug report at http://bugs.php.net/?id=30852&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30852&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30852&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30852&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30852&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30852&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30852&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30852&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30852&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30852&r=support Expected behavior: http://bugs.php.net/fix.php?id=30852&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30852&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30852&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30852&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30852&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30852&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30852&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30852&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30852&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30852&r=mysqlcfg