ID:               40517
 Updated by:       [EMAIL PROTECTED]
 Reported By:      djgrrr+phpbugs at p2p-network dot net
-Status:           Open
+Status:           Closed
 Bug Type:         Documentation problem
 Operating System: Linux 2.6
 PHP Version:      5.2.1
 New Comment:

A note has been added to the documentation about the timeout parameter.


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

[2007-02-20 17:32:52] djgrrr+phpbugs at p2p-network dot net

you completely missed my point..
stream_select() should return the failed aysnc connections as readable
connections after the timeout parameter has elapsed. I know for a fact
that this can be done, and its not hard to implement either.

Also, i use stream_get_meta_data() because feof() has a bug where it
locks up randomly for no reason, where as stream_get_meta_data() does
not. Don't try to tell me my code is flawed when i know its not.

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

[2007-02-20 16:01:24] [EMAIL PROTECTED]

The timeout parameter for stream_socket_client() only applies if you
are not making an async connection attempt.  When you ask for an async
connection attempt, the function returns "immediately" and so cannot
possibly wait for the connection timeout interval.

The correct way to detect whether an async connection has completed is
to use stream_select() and wait for the socket to become readable.  If
reading from that socket gives you an error, then the connection
attempt failed.

Also note that you really should not be using stream_get_meta_data() to
determine anything about the status of a network connection unless you
understand exactly how the PHP streams internals function.  The manual
states this very clearly--your code is broken if you use it for any
kind of logic in your script.

Making this into a documentation problem.



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

[2007-02-19 13:18:34] djgrrr+phpbugs at p2p-network dot net

<?php
$host = 'tcp://72.232.216.58:56004';
$sock = stream_socket_client($host, $errno, $err, 5,
(STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT));
stream_set_blocking($sock, false);

while (isset($sock)) {
  $r = array($sock);
  $w = $e = NULL;
  stream_select($r, $w, $e, 1, 0);

  if (count($r) > 0) {
    echo "Ready to read:\n";
    foreach($r as $rr) {
      $md = stream_get_meta_data($rr);
      var_dump($md, feof($rr), fgets($rr));
      fclose($rr);
      unset($sock);
      echo $host."\n";
    }
  }
}
?>

The above code should cause the stream_select to return a readable
connection after 5 seconds (in reality it takes around 3 minutes),
which when read from will return false, indicating its a failed
connection attempt. It would be nice if eof was set on the stream,
because the stream technically is at its end (although i'm not sure if
that would affect the use of stream_select or not).

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

[2007-02-19 09:46:08] [EMAIL PROTECTED]

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.



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

[2007-02-17 16:05:43] djgrrr+phpbugs at p2p-network dot net

Description:
------------
when using stream_socket_client() with the flags (STREAM_CLIENT_CONNECT
| STREAM_CLIENT_ASYNC_CONNECT), the async connection does not obey the
timeout parameter.

Also, when the connection does time out (after around 3 minutes) it
does not set the eof flag; although it does return false if you try to
read from the connection, it would also make a lot of sense if the eof
flag was also set on the resource, so calls to feof() return true. 



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


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

Reply via email to