• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/web/http/socket/stream.php
  • Класс: BitrixMainWebHttpSocketStream
  • Вызов: Stream::connect
public function connect(): void
{
	$context = stream_context_create($this->contextOptions);
	$flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT;

	// $context can be FALSE
	if ($context)
	{
		$res = stream_socket_client($this->address, $errno, $errstr, $this->socketTimeout, $flags, $context);
	}
	else
	{
		$res = stream_socket_client($this->address, $errno, $errstr, $this->socketTimeout, $flags);
	}

	if (is_resource($res))
	{
		$this->resource = $res;

		if ($this->streamTimeout > 0)
		{
			stream_set_timeout($this->resource, $this->streamTimeout);
			$this->lastTime = time();
		}

		$this->setBlocking(false);
	}
	else
	{
		throw new RuntimeException($errno > 0 ? "[{$errno}] {$errstr}" : 'Socket connection error.');
	}
}