1. Go to this page and download the library: Download ilexn/swoole-convent-psr7 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/ */
ilexn / swoole-convent-psr7 example snippets
php
declare(strict_types=1);
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseInterface;
use Swoole\Http\Response;
use Swoole\Http\Request;
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17Factory
);
$app = new Slim\App($psr17Factory);
$app->get('/hello/{name}', function ($request, ResponseInterface $response, $args) {
//dump($args);
$response->getBody()->write("Hello, " . $args['name']);
return $response->withHeader('X-Powered-By','ilexn');
});
$http->on('start', function ($server) {
echo "Swoole http server is started at http://127.0.0.1:9501\n";
});
$http->on('request',
function (Request $request, Response $response) use ($serverRequestFactory , $app
) {
$psr7Request = $serverRequestFactory->createFromSwoole($request);
$psr7Response = $app->handle($psr7Request);
$converter = new \Ilex\SwoolePsr7\SwooleResponseConverter($response);
$converter->send($psr7Response);
});
$http->start();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.