@@ -26,7 +26,7 @@ final class SocketStream extends AbstractStream
26
26
private $ url ;
27
27
private $ host = 'localhost ' ;
28
28
private $ port = 465 ;
29
- private $ timeout = 5 ;
29
+ private $ timeout ;
30
30
private $ tls = true ;
31
31
private $ sourceIp ;
32
32
private $ streamContextOptions = [];
@@ -40,7 +40,7 @@ public function setTimeout(float $timeout): self
40
40
41
41
public function getTimeout (): float
42
42
{
43
- return $ this ->timeout ;
43
+ return $ this ->timeout ?? ( float ) ini_get ( ' default_socket_timeout ' ) ;
44
44
}
45
45
46
46
/**
@@ -134,17 +134,18 @@ public function initialize(): void
134
134
$ 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;
135
135
$ streamContext = stream_context_create ($ options );
136
136
137
+ $ timeout = $ this ->getTimeout ();
137
138
set_error_handler (function ($ type , $ msg ) {
138
139
throw new TransportException (sprintf ('Connection could not be established with host "%s": %s. ' , $ this ->url , $ msg ));
139
140
});
140
141
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 );
142
143
} finally {
143
144
restore_error_handler ();
144
145
}
145
146
146
147
stream_set_blocking ($ this ->stream , true );
147
- stream_set_timeout ($ this ->stream , $ this -> timeout );
148
+ stream_set_timeout ($ this ->stream , $ timeout );
148
149
$ this ->in = &$ this ->stream ;
149
150
$ this ->out = &$ this ->stream ;
150
151
}
0 commit comments