runtime / swoole
Swoole runtime
0.4.0
2023-12-12 11:39 UTC
Requires
- php: >=8.1
- symfony/runtime: ^5.4.26 || ^6.3.2 || ^7.0
Requires (Dev)
- illuminate/http: ^9.14
- phpunit/phpunit: ^9.6.15
- swoole/ide-helper: ^4.6
- symfony/http-foundation: ^5.4.32 || ^6.3.9 || ^7.0
- symfony/http-kernel: ^5.4.33 || ^6.3.10 || ^7.0
Conflicts
- ext-swoole: <4.6.0
README
为 Swoole 提供运行时。
如果您对 Symfony Runtime 组件不熟悉,请阅读 主说明 了解更多。
安装
composer require runtime/swoole
使用方法
为您的应用程序定义环境变量 APP_RUNTIME
。
APP_RUNTIME=Runtime\Swoole\Runtime
纯 PHP
// public/index.php use Swoole\Http\Request; use Swoole\Http\Response; require_once dirname(__DIR__) . '/vendor/autoload_runtime.php'; return function () { return function (Request $request, Response $response) { $response->header("Content-Type", "text/plain"); $response->end("Hello World\n"); }; };
Symfony
// public/index.php use App\Kernel; require_once dirname(__DIR__) . '/vendor/autoload_runtime.php'; return function (array $context) { return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); };
使用选项
您可以使用 Symfony 的 Runtime APP_RUNTIME_OPTIONS
API 定义一些配置。
// public/index.php use App\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_once dirname(__DIR__) . '/vendor/autoload_runtime.php'; return function (array $context) { return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); };