Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Http\Request->isCompleted(): bool
None
Returns true
if the request packet has finished parsed and reached the end of the data and `false if not
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+
<?php
use OpenSwoole\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);