PHP code example of skoro / slim-swoole-integration

1. Go to this page and download the library: Download skoro/slim-swoole-integration 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/ */

    

skoro / slim-swoole-integration example snippets


$server = new \Swoole\Http\Server('localhost', 9501);
$app = \Slim\Factory\AppFactory::create();

$app->get('/', function (\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response) {
    $response->getBody()->write('Hello');
    return $response;
});

$server->on('request', \Slim\Swoole\ServerRequestFactory::createRequestCallback($app));

$server->start();

// $server is created in the above example.
$server->on('start', function ($server) {
    $watcher = new \Slim\Swoole\FileWatchers\InotifyWatcher();
    $watcher->addFilePath('path to your project sources');

    // Reloader tracks the changes every 1000 ms.
    $reloader = new \Slim\Swoole\HotCodeReloader($watcher, $server, 1000);
    $reloader->start();
});