ID:               32979
 User updated by:  mjpph at stardust dot fi
 Reported By:      mjpph at stardust dot fi
-Status:           Feedback
+Status:           Open
 Bug Type:         CGI related
 Operating System: Linux (Fedora Core 3)
 PHP Version:      5CVS-2005-05-08 (dev)
 New Comment:

No I used http only as an examply not thinking that it doesn't actually
output anything straight away.

I used the example code on several services that output information
straight from connect without needing any input from the client. For
example port 25 welcome message and several others. Telnet straight
away you get a welcome. Use only fgets, you get a welcome. Use the
example code, you get nothing. Didn't try anything which actually
closes the connection after the output, as this isn't the case with my
own implementation either and shouldn't be a requirement anyway.

The case is always the same, fgets would get input straight away but
stream_select stays dead no matter how many times it loops and waits.
Setting the stream to blocking or non-blocking mode has no effect on
stream_select's behaviour on this case. The data in the buffer just
stays there and stream_select is completely ignorant about it. So, the
read wouldn't block (as I know there is data pending), but even despite
that stream_select returns 0 changed streams always. So it thinks that
read would block, in reality, it doesn't.

Partly unrelated: I have this code in a script which also selects
stdin. The stdin select works as expected, the stream_socket selecting
select doesn't. I had a perfectly working implementation with
socket-based functions which stalled at the selects right after I
changed to stream_socket-based functions.


Previous Comments:
------------------------------------------------------------------------

[2005-05-09 01:26:32] [EMAIL PROTECTED]

Is the server end of the socket talking http?
If not, does it send data to the client immediately upon client
connection (without expecting data from the client first)?
If not, stream_select() is working precisely as it should.

Also note that stream_select() tells you only if a read or write would
not block, not whether there actually is data pending.

------------------------------------------------------------------------

[2005-05-08 23:06:40] mjpph at stardust dot fi

The issue is the same when using stream_socket_server.
stream_socket_accept works as expected, but if you select the socket it
always returns 0, even if there is a pending connection which would be
returned with stream_socket_accept.

------------------------------------------------------------------------

[2005-05-08 22:50:58] mjpph at stardust dot fi

Correction to the previous comment. The fread has to be done before
every stream_select to obtain any other value from stream_select other
than 0. stream_get_meta_data also reports pending data as 0 before the
fread and non-zero value right after the 1 byte fread.

------------------------------------------------------------------------

[2005-05-08 22:46:55] mjpph at stardust dot fi

Also, adding "fread($c,1);" after stream_socket_client and before the
while loop enables correct functionality of the stream_select function
from that pont on.

------------------------------------------------------------------------

[2005-05-08 22:18:29] mjpph at stardust dot fi

Description:
------------
Using stream_socket_client or stream_socket_server to open a connection
fails to report correct values with stream_select. Using fread to get
one byte before stream_select suddenly makes stream_select work as
expected.
Without it stream_select returns 0 changed streams even though there is
data waiting. Service used as an endpoint is persistent and doesn't
close the connection after it's output. PHP is CLI-version.

Reproduce code:
---------------
$c = stream_socket_client("tcp://127.0.0.1:80");
while (1)
{
  $streams = array($c);
  if (stream_select($streams, $write=NULL, $except=NULL, 0, 5000)) {
    print "Data received\n";
  }
}

// IP:Port can be anything which outputs something after connection.

Expected result:
----------------
Text "Data received" after connection and output from the service. The
service can be anything which just outputs something right after
connect.

Actual result:
--------------
Nothing. stream_select returns 0 even though there is data waiting.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32979&edit=1

Reply via email to