PHP code example of swokit / http-server
1. Go to this page and download the library: Download swokit/http-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/ */
swokit / http-server example snippets
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Swokit\Http\Serer\HttpServer;
use Swokit\Http\Serer\Util\ClosureWrapper;
use PhpComp\Http\Message\HttpFactory;
$http = new HttpServer([
//
]);
$http->setRequestHandler(ClosureWrapper::create(function(ServerRequestInterface $r): ResponseInterface {
$psr7res = HttpFactory::createResponse();
$psr7res->write('hello. URI: '. (string)$r->getUri());
return $psr7res;
}));
$http->run();