Swoole FastCGI Client PSR Style

The Swoole FastCGI Client supports coroutines when executed inside a coroutine context like Co\run or within a go() call. The client also has support for PSR Style.


Example

<?php

use Swoole\FastCGI\HttpRequest;
use Swoole\FastCGI\HttpResponse;
use Swoole\Coroutine\FastCGI\Client;

// The FastCGI client must run within a coroutine context
Co\run(function()
{
    // We use a try-catch to process any errors if something goes wrong
    try
    {
        // Create a new client based on host and port, can also use a UnixSocket
        $client = new Swoole\Coroutine\FastCGI\Client('127.0.0.1', 9000);

        // Builds up the request we want to send, with many options...
        $request = (new Swoole\FastCGI\HttpRequest())
            ->withScriptFilename(__DIR__ . '/greeter.php')
            ->withMethod('POST')
            ->withBody(['who' => 'Swoole']);

        // Returns a Swoole\FastCGI\HttpResponse
        $response = $client->execute($request);

        echo "Result: {$response->getBody()}\n";
    }
    catch(Swoole\Coroutine\FastCGI\Client\Exception $exception)
    {
        echo "Error Code: {$exception->getCode()}\n";
        echo "Error Message: {$exception->getMessage()}\n";
    }
});