zerai / openswoole-runtime
A openswoole runtime component.
Installs: 10 411
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
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
A runtime for OpenSwoole.
If you are new to the Symfony Runtime component, read more in the main readme.
Installation
composer require zerai/openswoole-runtime
Usage
Define the environment variable APP_RUNTIME
for your application.
APP_RUNTIME=Zerai\OpenSwoole\Runtime
Pure 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']); };
Using Options
You can define some configurations using Symfony's 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']); };