|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36918 stream_set_blocking doesn't work
Submitted: 2006-03-30 00:30 UTC Modified: 2007-07-17 13:30 UTC
Avg. Score:4.6 ± 0.6
Reproduced:8 of 9 (88.9%)
Same Version:2 (25.0%)
Same OS:2 (25.0%)
From: brud5_99 at yahoo dot com Assigned: jani (profile)
Status: Closed Package: Streams related
PHP Version: 5.1.2 OS: linux (gentoo)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: brud5_99 at yahoo dot com
New email:
PHP Version: OS:


 [2006-03-30 00:30 UTC] brud5_99 at yahoo dot com
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 
Php is configured as stand-alone, not as an apache module.

Thanks a lot for any help you can provide!

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

Reproduce code:
set_time_limit (0); error_reporting (2047);
$sock = stream_socket_server("tcp://", $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"; }
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-30 11:36 UTC]
Please try using this CVS snapshot:
For Windows:

That's exactly what I get: lots of "keep looping" and notices.
 [2006-03-30 15:10 UTC] brud5_99 at yahoo dot com
Thank you for the quick reply. Unfortunately the latest 
version didn't fix the problem for me. 
It still only loops until a connection is made.
Once the connection is established, it gets stuck on "loop1". 
Then it runs a whole loop once if you send input, and stops on 
loop1 again. 
If you disconnect it resumes looping.
 [2006-04-10 12:26 UTC]
Wez, I remember you bogusing similar bugs like this before..perhaps you have some insight on this.
 [2007-07-17 13:25 UTC]
Your code is a bit buggy, I can't get it working even after fixing the bug. See bug #36796 for a bit better (simpler :) example.

 [2007-07-17 13:30 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 19:01:30 2024 UTC