A runtime for Swoole.
If you are new to the Symfony Runtime component, read more in the main readme.
composer require runtime/swoole
Define the environment variable APP_RUNTIME for your application.
APP_RUNTIME=Runtime\Swoole\Runtime
// public/index.phpuseSwoole\Http\Request;
useSwoole\Http\Response;
require_oncedirname(__DIR__) . '/vendor/autoload_runtime.php';
returnfunction () {
returnfunction (Request$request, Response$response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello World\n");
};
};// public/index.phpuseApp\Kernel;
require_oncedirname(__DIR__) . '/vendor/autoload_runtime.php';
returnfunction (array$context) {
returnnewKernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};You can define some configurations using Symfony's Runtime APP_RUNTIME_OPTIONS API.
| Option | Description | Default |
|---|---|---|
host | The host where the server should binds to (precedes SWOOLE_HOST environment variable) | 127.0.0.1 |
port | The port where the server should be listing (precedes SWOOLE_PORT environment variable) | 8000 |
mode | Swoole's server mode (precedes SWOOLE_MODE environment variable) | SWOOLE_PROCESS |
settings | All Swoole's server settings (wiki.swoole.com/en/#/server/setting and wiki.swoole.com/en/#/http_server?id=configuration-options) | [] |
// public/index.phpuseApp\Kernel;
$_SERVER['APP_RUNTIME_OPTIONS'] = [
'host' => '0.0.0.0',
'port' => 9501,
'mode' => SWOOLE_BASE,
'settings' => [
'worker_num' => swoole_cpu_num() * 2,
'enable_static_handler' => true,
'document_root' => dirname(__DIR__) . '/public'
],
];
require_oncedirname(__DIR__) . '/vendor/autoload_runtime.php';
returnfunction (array$context) {
returnnewKernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};