zerai / openswoole-runtime
一个 openswoole 运行时组件。
0.1.0
2022-12-30 02:46 UTC
Requires
- php: >=8.0.5
- ext-openswoole: ^22.0
- symfony/runtime: ^5.4 || ^6.0
- webmozart/assert: ^1.9
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- illuminate/http: ^9.14
- openswoole/ide-helper: ^22.0
- phpunit/phpunit: ^9.5
- symfony/http-foundation: ^5.4 || ^6.0
- symfony/http-kernel: ^5.4 || ^6.0
README
为 OpenSwoole 提供运行时。
如果您是 Symfony 运行时组件的新手,请参阅 主 README 了解更多。
安装
composer require zerai/openswoole-runtime
用法
为您的应用程序定义环境变量 APP_RUNTIME
。
APP_RUNTIME=Zerai\OpenSwoole\Runtime
纯 PHP
// public/index.php use OpenSwoole\Http\Request; use OpenSwoole\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_PROCESS, 'hot-reload' => false, 'settings' => [ \Swoole\Constant::OPTION_WORKER_NUM => 2, \Swoole\Constant::OPTION_ENABLE_STATIC_HANDLER => true, \Swoole\Constant::OPTION_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']); };