zerai/openswoole-runtime
A openswoole runtime component.
11,357
1
| Install | |
|---|---|
composer require zerai/openswoole-runtime |
|
| Latest Version: | 0.1.0 |
| PHP: | >=8.0.5 |
| License: | MIT |
| Last Updated: | Dec 31, 2022 |
| Links: | GitHub · Packagist |
Maintainer: teclaizerai
OpenSwoole Runtime
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.
| 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 |
hot_reload |
Enable server hot reload mode (precedes SWOOLE_HOT_RELOAD environment variable). Require server mode as SWOOLE_PROCESS |
0 |
settings |
All Swoole's server settings (https://openswoole.com/docs/modules/swoole-http-server/configuration) | [] |
// 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']);
};
Related Packages
blest/blest
The PHP reference implementation of BLEST (Batch-able, Lightweight, Encrypted St...
32
0
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
651,963,193
9,701
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| 0.1.0 | >=8.0.5 | MIT |