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

public method

Opens a curl connection and initializes the internal resource handle.

Parameters

  • array $options

    update the config settings if $options['options'] exists, will be passed to $this->set()

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 = array()) {
		$this->options = array();
		parent::open($options);
		$config = $this->_config;

		if (empty($config['scheme']) || empty($config['host'])) {
			return false;
		}
		if (!empty($config['options'])) {
			$this->set($config['options']);
		}

		$url = "{$config['scheme']}://{$config['host']}";
		$this->_resource = curl_init($url);
		$this->set(array(
			CURLOPT_PORT => $config['port'],
			CURLOPT_HEADER => true,
			CURLOPT_RETURNTRANSFER => true
		));

		if (!is_resource($this->_resource)) {
			return false;
		}
		$this->_isConnected = true;
		$this->timeout($config['timeout']);

		if (isset($config['encoding'])) {
			$this->encoding($config['encoding']);
		}
		return $this->_resource;
	}