1. Go to this page and download the library: Download pachico/slim-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/ */
php
use Pachico\SlimSwoole\BridgeManager;
use Slim\Http;
cation
* For the sake of demonstration, we also add a simple middleware
* to check that the entire app stack is being setup and executed
* properly.
*/
$app = new \Slim\App();
$app->any('/foo[/{myArg}]', function (Http\Request $request, Http\Response $response, array $args) {
$data = [
'args' => $args,
'body' => (string) $request->getBody(),
'parsedBody' => $request->getParsedBody(),
'params' => $request->getParams(),
'headers' => $request->getHeaders(),
'uploadedFiles' => $request->getUploadedFiles()
];
return $response->withJson($data);
})->add(function (Http\Request $request, Http\Response $response, callable $next) {
$response->getBody()->write('BEFORE' . PHP_EOL);
$response = $next($request, $response);
$response->getBody()->write(PHP_EOL . 'AFTER');
return $response;
});
/**
* We instanciate the BridgeManager (this library)
*/
$bridgeManager = new BridgeManager($app);
/**
* We start the Swoole server
*/
$http = new swoole_http_server("0.0.0.0", 8081);
/**
* We register the on "start" event
*/
$http->on("start", function (\swoole_http_server $server) {
echo sprintf('Swoole http server is started at http://%s:%s', $server->host, $server->port), PHP_EOL;
});
/**
* We register the on "request event, which will use the BridgeManager to transform request, process it
* as a Slim request and merge back the response
*
*/
$http->on(
"request",
function (swoole_http_request $swooleRequest, swoole_http_response $swooleResponse) use ($bridgeManager) {
$bridgeManager->process($swooleRequest, $swooleResponse)->end();
}
);
$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.