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

Latest version: pecl install openswoole-22.1.2


The 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:


$request = (new Swoole\FastCGI\HttpRequest())
            ->withScriptFilename(__DIR__ . '/tmp/var_dump.php')
            ->withHeader('X-Foo', 'bar')
            ->withHeader('X-Bar', 'char')
            ->withHeaders(['X-Name' => 'Swoole', 'X-Age' => 23])
            ->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:


$client = new Swoole\Coroutine\FastCGI\Client('', 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.

Last updated on August 31, 2022