55 $context = stream_context_create($this->contextOptions);
57 $flags = STREAM_CLIENT_CONNECT;
60 $flags |= STREAM_CLIENT_ASYNC_CONNECT;
64 set_error_handler(
function ($errno, $errstr) {
65 throw new \RuntimeException(
"[{$errno}] {$errstr}");
73 $res = stream_socket_client($this->address, $errno, $errstr, $this->socketTimeout, $flags,
$context);
77 $res = stream_socket_client($this->address, $errno, $errstr, $this->socketTimeout, $flags);
82 restore_error_handler();
85 if (is_resource(
$res))
87 $this->resource =
$res;
89 if ($this->streamTimeout > 0)
91 stream_set_timeout($this->resource, $this->streamTimeout);
92 $this->lastTime = time();
102 throw new \RuntimeException($errno > 0 ?
"[{$errno}] {$errstr}" :
'Socket connection error.');