Join 2,000+ others and never miss out on new tips, tutorials, and more.
pecl install openswoole-4.11.1
Swoole\FastCGI\HttpRequest is an object which is used when calling
Swoole\\Coroutine\\FastCGI\\Client->execute, you first build up a request you want to send, pass it over to
execute and the client will handle the request for you based on the object you give. You set the request options and data within this object.
You may have already seen a few examples using this request object, if not it may be good to look at the advanced example to see how the request object is used in proper context. The example shown here is just showing common and most widely used methods:
<?php $request = (new Swoole\FastCGI\HttpRequest()) ->withScheme('http') ->withDocumentRoot(__DIR__) ->withScriptFilename(__DIR__ . '/tmp/var_dump.php') ->withScriptName('var_dump.php') ->withMethod('POST') ->withContentType('x-www-form-urlencoded') ->withContentLength(128) ->withUri('/tmp/var_dump?foo=bar&bar=char') ->withHeader('X-Foo', 'bar') ->withHeader('X-Bar', 'char') ->withHeaders(['X-Name' => 'Swoole', 'X-Age' => 23]) ->withRedirectStatus(200) ->withBody(['foo' => 'bar', 'bar' => 'char']);
Once you have built your request object with all the options and data you want to use, you can execute that request by doing something like:
<?php $client = new Swoole\Coroutine\FastCGI\Client('127.0.0.1', 9000); ... $response = $client->execute($request);
For a full example checkout the advanced example which shows proper context and use.
The methods shown in the example are only the most commonly used ones, there are more methods to explore, please see the [source code](advanced example) for this object to see what other methods are available.
Once you have made a request you and its successful, you will have a response object in return, you can use this to access information and data from the response.