PHP code example of tijmen-wierenga / async-php-server

1. Go to this page and download the library: Download tijmen-wierenga/async-php-server 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/ */

    

tijmen-wierenga / async-php-server example snippets


$connection = \TijmenWierenga\Server\Connection::init(9000, '0.0.0.0'); 

class HelloWorld implements TijmenWierenga\Server\RequestHandler
{
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return new Response(200, ['Content-Type' => 'text/plain'], "Hello World!");
    }
}
 bash
git clone https://github.com/TijmenWierenga/async-php-server.git
 bash
php example/demo-server.php 
 bash
docker run \
    --rm \
    -t \
    -d \
    -v ~/www/server:/var/www/html \
    --name async_php_server \
    php:7.1-fpm-alpine \
    php /var/www/html/example/demo-server.php
 bash 
docker logs async_php_server
 bash 
docker exec async_php_server curl -H "Content-Type: application/json" -X POST -d '{"name":"tijmen","age":30}' http://localhost:9000
 php 
$parser = new TijmenWierenga\Server\DefaultParser(new \Nathanmac\Utilities\Parser\Parser());
 php
$server = new TijmenWierenga\Server\AsyncServer($connection, $requestHandler, $parser);
$server->run();