예제 #1
0
파일: TCP.php 프로젝트: pengzhile/purl
 protected function newClient()
 {
     $flag = STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT;
     $remote = 'tcp://' . $this->ip . ':' . $this->port;
     $fp = stream_socket_client($remote, $errNo, $errStr, 0, $flag);
     Helper::assert(false !== $fp, 'Unable to init stream, code: ' . $errNo);
     return $fp;
 }
예제 #2
0
파일: SSL.php 프로젝트: pengzhile/purl
 protected function newClient()
 {
     $flag = STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT;
     $remote = 'tls://' . $this->ip . ':' . $this->port;
     $options = array('ssl' => array('peer_name' => $this->host, 'disable_compression' => true, 'SNI_enabled' => true, 'cafile' => __DIR__ . '/cacert.pem', 'verify_depth' => 7, 'verify_peer' => $this->verifyCert, 'verify_peer_name' => $this->verifyCert, 'allow_self_signed' => !$this->verifyCert));
     if (PHP_VERSION_ID < 50600) {
         $options['ssl']['CN_match'] = $this->host;
         $options['ssl']['SNI_server_name'] = $this->host;
     }
     $context = stream_context_create($options);
     $fp = stream_socket_client($remote, $errNo, $errStr, $this->connTimeout / 1000000, $flag, $context);
     Helper::assert(false !== $fp, 'Unable to init stream, code: ' . $errNo);
     return $fp;
 }
예제 #3
0
 protected function add($method, $url, $callback, array $headers = null, array $data = null)
 {
     static $id = 0;
     ++$id;
     $info = new UrlInfo($url);
     $ip = Helper::host2ip($info->getHost());
     $parser = new Parser();
     if ('http' === $info->getScheme()) {
         $stream = new TCP($id, $ip, $info->getPort(), $parser);
     } elseif ('https' === $info->getScheme()) {
         $stream = new SSL($id, $info->getHost(), $ip, $info->getPort(), $parser, $this->connTimeout, $this->verifyCert);
     } else {
         throw new Exception('Unsupported url');
     }
     $stream->addRequest(new Request($method, $info, $headers, $data), $callback);
     $this->event->onWrite($stream->getResource(), array($this, 'sendCallback'), $stream, $this->connTimeout);
     return $id;
 }