@@ -190,19 +190,12 @@ private function receive($len = null)
190
190
* @return resource
191
191
* @throws \Exception Exception raised if connection fails.
192
192
*/
193
- private function getStream ($ address, $ timeout = null )
193
+ private function getStream ($ address )
194
194
{
195
- if (is_null ($ timeout )) {
196
- $ timeout = intval (ini_get ('default_socket_timeout ' ));
197
- }
198
195
$ errno = null ;
199
196
$ errstr = null ;
200
197
201
- $ fp = stream_socket_client ($ address , $ errno , $ errstr , $ timeout , STREAM_CLIENT_CONNECT );
202
- $ timeout = number_format ($ timeout , 3 );
203
- $ seconds = floor ($ timeout );
204
- $ microseconds = ($ timeout - $ seconds ) * 1000 ;
205
- stream_set_timeout ($ fp , $ seconds , $ microseconds );
198
+ $ fp = stream_socket_client ($ address , $ errno , $ errstr , null , STREAM_CLIENT_CONNECT );
206
199
207
200
if (!$ fp ) {
208
201
throw new \Exception ($ errstr , $ errno );
@@ -231,9 +224,13 @@ public function isConnected()
231
224
*/
232
225
public function connect ($ timeout = null )
233
226
{
227
+ if ($ timeout === null ) {
228
+ $ timeout = intval (ini_get ('default_socket_timeout ' ));
229
+ }
234
230
235
231
$ this ->timeout = $ timeout ;
236
- $ this ->streamSocket = $ this ->getStream ($ this ->options ->getAddress (), $ timeout );
232
+ $ this ->streamSocket = $ this ->getStream ($ this ->options ->getAddress ());
233
+ $ this ->setStreamTimeout ($ timeout );
237
234
238
235
$ msg = 'CONNECT ' .$ this ->options ;
239
236
$ this ->send ($ msg );
@@ -447,9 +444,12 @@ public function wait($quantity = 0)
447
444
public function setStreamTimeout ($ seconds )
448
445
{
449
446
if ($ this ->isConnected ()) {
450
- if (is_int ($ seconds )) {
447
+ if (is_numeric ($ seconds )) {
451
448
try {
452
- return stream_set_timeout ($ this ->streamSocket , $ seconds );
449
+ $ timeout = number_format ($ seconds , 3 );
450
+ $ seconds = floor ($ timeout );
451
+ $ microseconds = ($ timeout - $ seconds ) * 1000 ;
452
+ return stream_set_timeout ($ this ->streamSocket , $ seconds , $ microseconds );
453
453
} catch (\Exception $ e ) {
454
454
return false ;
455
455
}
0 commit comments