open() публичный Метод

Opens the socket and sets Socket::$_resource.
public open ( array $options = [] ) : mixed
$options array Update the config settings.
Результат mixed The open resource on success, `false` otherwise.
Пример #1
0
 /**
  * Connect to data source.
  *
  * @return boolean
  */
 public function connect()
 {
     if (!$this->_isConnected && $this->_connection) {
         $this->_isConnected = $this->_connection->open();
     }
     return $this->_isConnected;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 public function open(array $options = array())
 {
     parent::open($options);
     return true;
 }