@@ -26,7 +26,7 @@ final class SocketStream extends AbstractStream
2626 private $ url ;
2727 private $ host = 'localhost ' ;
2828 private $ port = 465 ;
29- private $ timeout = 5 ;
29+ private $ timeout ;
3030 private $ tls = true ;
3131 private $ sourceIp ;
3232 private $ streamContextOptions = [];
@@ -40,7 +40,7 @@ public function setTimeout(float $timeout): self
4040
4141 public function getTimeout (): float
4242 {
43- return $ this ->timeout ;
43+ return $ this ->timeout ?? ( float ) ini_get ( ' default_socket_timeout ' ) ;
4444 }
4545
4646 /**
@@ -134,17 +134,18 @@ public function initialize(): void
134134 $ options ['ssl ' ]['crypto_method ' ] = $ options ['ssl ' ]['crypto_method ' ] ?? STREAM_CRYPTO_METHOD_TLS_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
135135 $ streamContext = stream_context_create ($ options );
136136
137+ $ timeout = $ this ->getTimeout ();
137138 set_error_handler (function ($ type , $ msg ) {
138139 throw new TransportException (sprintf ('Connection could not be established with host "%s": %s. ' , $ this ->url , $ msg ));
139140 });
140141 try {
141- $ this ->stream = stream_socket_client ($ this ->url , $ errno , $ errstr , $ this -> timeout , STREAM_CLIENT_CONNECT , $ streamContext );
142+ $ this ->stream = stream_socket_client ($ this ->url , $ errno , $ errstr , $ timeout , STREAM_CLIENT_CONNECT , $ streamContext );
142143 } finally {
143144 restore_error_handler ();
144145 }
145146
146147 stream_set_blocking ($ this ->stream , true );
147- stream_set_timeout ($ this ->stream , $ this -> timeout );
148+ stream_set_timeout ($ this ->stream , $ timeout );
148149 $ this ->in = &$ this ->stream ;
149150 $ this ->out = &$ this ->stream ;
150151 }
0 commit comments