Workerman\Connection\TcpConnection::close PHP Method

close() public method

Close connection.
public close ( mixed $data = null, boolean $raw = false ) : void
$data mixed
$raw boolean
return void
    public function close($data = null, $raw = false)
    {
        if ($this->_status === self::STATUS_CLOSING || $this->_status === self::STATUS_CLOSED) {
            return;
        } else {
            if ($data !== null) {
                $this->send($data, $raw);
            }
            $this->_status = self::STATUS_CLOSING;
        }
        if ($this->_sendBuffer === '') {
            $this->destroy();
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Check the integrity of the package.
  *
  * @param string        $recv_buffer
  * @param TcpConnection $connection
  * @return int
  */
 public static function input($recv_buffer, TcpConnection $connection)
 {
     if (!strpos($recv_buffer, "\r\n\r\n")) {
         // Judge whether the package length exceeds the limit.
         if (strlen($recv_buffer) >= TcpConnection::$maxPackageSize) {
             $connection->close();
             return 0;
         }
         return 0;
     }
     list($header, ) = explode("\r\n\r\n", $recv_buffer, 2);
     if (0 === strpos($recv_buffer, "POST")) {
         // find Content-Length
         $match = array();
         if (preg_match("/\r\nContent-Length: ?(\\d+)/i", $header, $match)) {
             $content_length = $match[1];
             return $content_length + strlen($header) + 4;
         } else {
             return 0;
         }
     } elseif (0 === strpos($recv_buffer, "GET")) {
         return strlen($header) + 4;
     } else {
         $connection->send("HTTP/1.1 400 Bad Request\r\n\r\n", true);
         return 0;
     }
 }
All Usage Examples Of Workerman\Connection\TcpConnection::close