Swoole\Http\Request->isCompleted()

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Http\Request->isCompleted(): bool

Parameters

None

Return

Bool

Returns true if the request packet has finished parsed and reached the end of the data and `false if not

Description

Check if a HTTP request packet is completed when the server is parsing the HTTP request with the $request->parse($data) API. You can use this to create your own request parser.

Since version 4.6.0+

Example

<?php
use Swoole\Http\Request;

$data = "GET /something?hello=world&test=2123 HTTP/1.1\r\n";
$data .= "Host: 127.0.0.1\r\n";
$data .= "Connection: keep-alive\r\n";
$data .= "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36\r\n";
$data .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n";
$data .= "Accept-Encoding: gzip, deflate, br\r\n";

$request = Request::create(['parse_cookie' => false]);
var_dump($request);

var_dump($request->isCompleted());
var_dump($request->parse($data));

var_dump($request->parse("\r\n"));
var_dump($request->isCompleted());

// Parsing cookies is turned off, so it will be null
var_dump($request);
var_dump($request->cookie);
Last updated on August 31, 2022