@@ -10,32 +10,35 @@ class StreamWrapper
1010 /**
1111 * Wrapper for stream_socket_client
1212 *
13- * @param string $address Address to connect the socket.
14- * @param integer $errno Number of error.
15- * @param string $errstr Description of error.
16- * @param integer $timeout Timeout.
13+ * @param string $address Address to connect the socket.
14+ * @param integer $errno Number of error.
15+ * @param string $errstr Description of error.
16+ * @param float $timeout Timeout.
1717 * @param integer $typeStream Type of stream.
1818 *
1919 * @return resource
2020 */
2121 public function getStreamSocketClient ($ address , &$ errno , &$ errstr , $ timeout , $ typeStream )
2222 {
2323 $ stream = stream_socket_client ($ address , $ errno , $ errstr , $ timeout , $ typeStream );
24- stream_set_timeout ($ stream , $ timeout );
24+ $ this -> setStreamTimeout ($ stream , $ timeout );
2525 return $ stream ;
2626 }
27-
27+
2828 /**
2929 * Wrapper for stream_set_timeout
3030 *
31- * @param mixed $stream Stream.
32- * @param integer $seconds Seconds for timeout.
31+ * @param mixed $stream Stream.
32+ * @param float $seconds Seconds for timeout.
3333 *
3434 * @return boolean
3535 *
36- */
36+ */
3737 public function setStreamTimeout ($ stream , $ seconds )
3838 {
39- return stream_set_timeout ($ stream , $ seconds );
39+ $ timeout = number_format ($ seconds , 3 );
40+ $ seconds = floor ($ timeout );
41+ $ microseconds = ($ timeout - $ seconds ) * 1000 ;
42+ return stream_set_timeout ($ stream , $ seconds , $ microseconds );
4043 }
4144}
0 commit comments