Example #1
0
 /**
  * @param boolean $repeat whether it is repeat connection
  * @return resource the connection socket
  */
 protected function openSock($repeat = false)
 {
     $this->delSockRef();
     $this->flag |= self::FLAG_NEW;
     if ($repeat === true) {
         $this->flag |= self::FLAG_NEW2;
     }
     // async-connect
     $this->sock = stream_socket_client($this->conn, $errno, $error, 1, STREAM_CLIENT_ASYNC_CONNECT);
     if ($this->sock === false) {
         Client::debug($repeat ? 're' : '', 'open \'', $this->conn, '\' failed: ', $error);
         self::$_lastError = $error;
     } else {
         Client::debug($repeat ? 're' : '', 'open \'', $this->conn, '\' success: ', $this->sock);
         stream_set_blocking($this->sock, false);
         $this->flag |= self::FLAG_OPENED;
         $this->addSockRef();
     }
     $this->outBuf = null;
     $this->outLen = 0;
     return $this->sock;
 }
Example #2
0
 private function getRequestBuf()
 {
     // request line
     $cli = $this->cli;
     $req = $this->req;
     $pa = $req->getUrlParams();
     $header = $req->getMethod() . ' ' . $pa['path'];
     if (isset($pa['query'])) {
         $header .= '?' . $pa['query'];
     }
     $header .= ' HTTP/1.1' . Client::CRLF;
     // body (must call prior than headers)
     $body = $req->getBody();
     Client::debug('request body(', strlen($body) . ')');
     // header
     $cli->applyCookie($req);
     foreach (array_merge($cli->getHeader(null), $req->getHeader(null)) as $key => $value) {
         $header .= $this->formatHeaderLine($key, $value);
     }
     Client::debug('request header: ', Client::CRLF, $header);
     return $header . Client::CRLF . $body;
 }