lithium\net\socket\Context::open()

public method

Opens the socket and sets its timeout value.

Parameters

  • array $options

    Update the config settings.

Returns

mixed

Returns false if the socket configuration does not contain the 'scheme' or 'host' settings, or if configuration fails, otherwise returns a resource stream.

Source

	public function open(array $options = []) {
		parent::open($options);
		$config = $this->_config;

		if (!$config['scheme'] || !$config['host']) {
			return false;
		}
		$url = "{$config['scheme']}://{$config['host']}:{$config['port']}";
		$context = [$config['scheme'] => ['timeout' => $this->_timeout]];

		if (is_object($config['message'])) {
			$url = $config['message']->to('url');
			$context = $config['message']->to('context', ['timeout' => $this->_timeout]);
		}
		$this->_resource = fopen($url, $config['mode'], false, stream_context_create($context));
		return $this->_resource;
	}