示例#1
0
 public function read($length = 4096)
 {
     try {
         $this->read_buffer .= parent::read($length);
         $this->on_read();
     } catch (socketException $e) {
         $old_socket = (int) $this->socket;
         $this->close();
         $this->socket = $old_socket;
         $this->disconnected = true;
         $this->on_disconnect();
     }
 }
示例#2
0
 public function send(socket $socket, request $request)
 {
     if ($this->has_cookie()) {
         $request->add_header('Cookie', $this->get_cookie_header());
     }
     $request_message = $request->fetch();
     // echo $request_message;
     $socket->write($request_message);
     $response = new response($socket->read());
     $cookies = $response->get_header('Set-Cookie');
     if ($cookies !== null) {
         if (is_array($cookies)) {
             foreach ($cookies as $cookie) {
                 $this->parse_cookie($cookie);
             }
         } else {
             $this->parse_cookie($cookies);
         }
     }
     return $response;
 }