Detect timeout of stream_socket_client using STREAM_CLIENT_ASYNC_CONNECT ?

From: Date: Sat, 06 Nov 2010 18:58:37 +0000
Subject: Detect timeout of stream_socket_client using STREAM_CLIENT_ASYNC_CONNECT ?
Groups: php.general 
Request: Send a blank email to php-general+get-309354@lists.php.net to get a copy of this message
(apologies if this sends twice - email verification issues) Is it possible to detect the timeout of a stream created with stream_socket_client() using the flag 'STREAM_CLIENT_ASYNC_CONNECT' ? As soon as this flag is used, it seems there is no way to detect a timeout situation. tcp://192.168.100.100:123 is a fictional, non-existent endpoint. Code: ======================= <?php ini_set('default_socket_timeout', 1); $flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT; $conn = stream_socket_client('tcp://192.168.100.100:123', $errNo, $errStr, 1, $flags); stream_set_timeout($conn, 1); $read = array($conn); $write = array($conn); $e = null; stream_select($read, $write, $e, 5, 0); var_dump($read); var_dump($write); var_dump($errNo); var_dump($errStr); var_dump(stream_get_meta_data($conn)); Output: ======================= array(0) { } array(0) { } int(0) string(0) "" array(7) { ["stream_type"]=> string(14) "tcp_socket/ssl" ["mode"]=> string(2) "r+" ["unread_bytes"]=> int(0) ["seekable"]=> bool(false) ["timed_out"]=> bool(false) ["blocked"]=> bool(true) ["eof"]=> bool(false) } Thanks

« previous php.general (#309354) next »