runtime / swoole
Swoole runtime
                                    Fund package maintenance!
                                                                            
                                                                                                                                        nyholm
                                                                                    
                                                                
Installs: 166 966
Dependents: 2
Suggesters: 0
Security: 0
Stars: 57
Watchers: 5
Forks: 8
pkg:composer/runtime/swoole
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
A runtime for Swoole.
If you are new to the Symfony Runtime component, read more in the main readme.
Installation
composer require runtime/swoole
Usage
Define the environment variable APP_RUNTIME for your application.
APP_RUNTIME=Runtime\Swoole\Runtime
Pure 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']); };
Using Options
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_HOSTenvironment variable) | 127.0.0.1 | 
| port | The port where the server should be listing (precedes SWOOLE_PORTenvironment variable) | 8000 | 
| mode | Swoole's server mode (precedes SWOOLE_MODEenvironment 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.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']); };