PHP code example of poa / httpserver

1. Go to this page and download the library: Download poa/httpserver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

poa / httpserver example snippets


use Poa\Http\Router\Router;
use Poa\Http\Server\HandleExceptionMiddleware;
use Poa\Http\Server\HttpApplication;
use Poa\Http\Server\HttpContext;
use Poa\Http\Server\HttpServerInterface;
use Poa\Middleware\ElapsedTimeMiddleware;
use Poa\Middleware\MiddlewareSystemInterface;

class FpmHttpServer implements HttpServerInterface
{
    protected MiddlewareSystemInterface $application;

    public function start()
    {
        $context = new HttpContext(null, null);
        $app = $this->application;
        $app($context);
    }

    public function stop()
    {
        // do nothing
    }

    public function delegateRequest(MiddlewareSystemInterface $application)
    {
        $this->application = $application;
    }
}

$app = new HttpApplication();
$app->use(new HandleExceptionMiddleware())
    ->use(new ElapsedTimeMiddleware())
    ->use(new Router());

$server = new FpmHttpServer();
$server->delegateRequest($app);
$server->start();