PHP code example of razonyang / psr7-swoole
1. Go to this page and download the library: Download razonyang/psr7-swoole 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/ */
razonyang / psr7-swoole example snippets
declare(strict_types=1);
ctory;
use Nyholm\Psr7\Stream;
use RazonYang\Psr7\Swoole\EmitterFactory;
use RazonYang\Psr7\Swoole\ServerRequestFactory;
use Swoole\Coroutine\Http\Server;
use function Swoole\Coroutine\run;
run(function () {
$serverRequestFactory = new ServerRequestFactory();
$emitterFactory = new EmitterFactory();
$psr7Factory =new Psr17Factory();
$server = new Server('127.0.0.1', 9501, false);
$server->handle('/', function ($request, $response) use ($emitterFactory, $serverRequestFactory, $psr7Factory) {
$emitter = $emitterFactory->create($response);
$psrRequest = $serverRequestFactory->create($request);
$psrResponse = $psr7Factory
->createResponse(200)
->withBody(Stream::create($psrRequest->getUri()->getPath()));
$emitter->emit($psrResponse);
});
$server->start();
});