/** * Opens a socket and initializes the internal resource handle. * * @param array $options update the config settings * @return mixed Returns `false` if the socket configuration does not contain the * `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a * resource stream. Throws exception if there is a network error. */ public function open(array $options = array()) { parent::open($options); $config = $this->_config; if (!$config['scheme'] || !$config['host']) { return false; } $scheme = $config['scheme'] !== 'udp' ? 'tcp' : 'udp'; $port = $config['port'] ?: 80; $host = "{$scheme}://{$config['host']}:{$port}"; $flags = STREAM_CLIENT_CONNECT; if ($config['persistent']) { $flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT; } $errorCode = $errorMessage = null; $this->_resource = stream_socket_client($host, $errorCode, $errorMessage, $config['timeout'], $flags); if ($errorCode || $errorMessage) { throw new NetworkException($errorMessage); } $this->timeout($config['timeout']); if (!empty($config['encoding'])) { $this->encoding($config['encoding']); } return $this->_resource; }
/** * Send request and return response data. * * @param string $method * @param string $path * @param array $data * @param array $options * @return string */ public function send($method, $path = null, $data = null, $options = array()) { $defaults = array('return' => 'body'); $options += $defaults; if (!$this->connect()) { return; } $request = $this->_request($method, $path, $data, $options); $response = $this->_connection->send($request, array('classes' => $this->_classes)); if ($response) { $this->last = (object) compact('request', 'response'); $this->disconnect(); return $options['return'] == 'body' ? $response->body() : $response; } }
/** * Opens the socket and sets its timeout value. * * @param array $options Update the config settings. * @return mixed Returns `false` if the socket configuration does not contain the * `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a * resource stream. */ public function open(array $options = array()) { parent::open($options); $config = $this->_config; if (!$config['scheme'] || !$config['host']) { return false; } $url = "{$config['scheme']}://{$config['host']}:{$config['port']}"; $context = array($config['scheme'] => array('timeout' => $this->_timeout)); if (is_object($config['message'])) { $url = $config['message']->to('url'); $context = $config['message']->to('context', array('timeout' => $this->_timeout)); } $this->_resource = fopen($url, $config['mode'], false, stream_context_create($context)); return $this->_resource; }
/** * Opens a curl connection and initializes the internal resource handle. * * @param array $options update the config settings * @return mixed Returns `false` if the socket configuration does not contain the * `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a * resource stream. */ public function open(array $options = array()) { $this->options = array(); parent::open($options); $config = $this->_config; if (empty($config['scheme']) || empty($config['host'])) { return false; } $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; }
public function open(array $options = array()) { parent::open($options); return true; }
public function __construct(array $config = array()) { $this->configs[] = $config; parent::__construct((array) $config); }
/** * Constructor * * @param array $config */ public function __construct(array $config = array()) { $defaults = array('mode' => 'r', 'message' => null); parent::__construct($config + $defaults); $this->timeout($this->_config['timeout']); }
/** * Constructor * * @param array $config */ public function __construct(array $config = array()) { $defaults = array('ignoreExpect' => true); parent::__construct($config + $defaults); }
/** * Constructor * * @param array $config */ public function __construct(array $config = array()) { $defaults = array('scheme' => 'http'); parent::__construct($config + $defaults); $this->timeout($this->_config['timeout']); }