1. Go to this page and download the library: Download sibidharan/zealphp 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/ */
// Built-in middleware
$app->addMiddleware(new \ZealPHP\Middleware\CorsMiddleware());
$app->addMiddleware(new \ZealPHP\Middleware\ETagMiddleware());
// HTTP compression is handled by OpenSwoole by default.
// Custom PSR-15 middleware
class TimingMiddleware implements MiddlewareInterface {
public function process(ServerRequestInterface $req, RequestHandlerInterface $next): ResponseInterface {
$start = microtime(true);
$response = $next->handle($req);
response_add_header('X-Time', round((microtime(true)-$start)*1000, 2).'ms');
return $response;
}
}
// Create BEFORE $app->run() — shared across all forked workers
$clientTable = Store::make('clients', 4096, [
'room' => [Store::TYPE_STRING, 64],
'uid' => [Store::TYPE_STRING, 128],
]);
$hitCounter = new Counter(0);
// In any route — every forked worker sees the same data
Store::set('clients', "$fd", ['room' => 'general', 'uid' => 'alice']);
$hitCounter->increment();