#36918 [NEW]: stream_set_blocking doesn't work
From: brud5_99 at yahoo dot com
Operating system: linux (gentoo)
PHP version: 5.1.2
PHP Bug Type: Streams related
Bug description: stream_set_blocking doesn't work
Description:
------------
stream_set_blocking seems to get ignored. There are no
errors or warnings, but the socket behaves as if it was set
to blocking.
The same code works as expected with php 5.0.1 on a FreeBsd
box, but not with 5.1.2 under gentoo linux. The piece of
code sample included is all that's needed to see the
problem.
Php is configured as stand-alone, not as an apache module.
Thanks a lot for any help you can provide!
bernie
./configure --without-pear --without-apache --with-sockets
--enable-sockets --with-mysql-sock=/tmp/mysql.sock --with-
mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/
mysql_config --enable-pcntl --enable-pcntl --enable-sysvshm
--enable-sysvsem --enable-sigchild --with-config-file-path=/
usr/local/phpForCgi/conf --prefix=/usr/local/phpForCgi --
sysconfdir=/usr/local/phpForCgi/conf
Reproduce code:
---------------
<?php
set_time_limit (0); error_reporting (2047);
$sock = stream_socket_server("tcp://0.0.0.0:7000", $errno, $errstr);
stream_set_blocking($sock, 0);
$counter = 0;
if (!isset($sockCount)) {$sockCount = 0; }
while(true) {
$msgsock[$sockCount] = @stream_socket_accept($sock, 0);
if (is_resource($msgsock[$sockCount])) { $sockCount++; }
$counter = 0;
while($counter < $sockCount + 1) {
if (is_resource($msgsock[$counter])) {
echo "loop1:\n";
$buf = fread($msgsock[$counter],2048);
echo "loop2: $buf\n";
}
echo "keep looping: $buf\n";
if ($buf) { echo "buf: $buf\n"; }
$counter++;
}
}
fclose ($sock);
?>
Expected result:
----------------
It should echo "keep looping" if there is no input
Actual result:
--------------
It keeps echoing "keep looping" until a connection is made.
After input was received (made a telnet connection to port
7000 and sent some text thru), the trace stops at "loop1".
Only about every 30sec(or so) it does a complete loop. I think
that is after fread() times out intenally.
Also, if the connction is closed, it keeps looping thru "keep
looping" again.
--
Edit bug report at http://bugs.php.net/?id=36918&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36918&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36918&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36918&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36918&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=36918&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36918&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36918&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36918&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36918&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36918&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=36918&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=36918&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36918&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36918&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36918&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36918&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36918&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36918&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36918&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36918&r=mysqlcfg
Thread (6 messages)
- brud5_99 at yahoo dot com