Files
wasl/Backend/config/octane.php
2026-06-20 21:55:06 +03:00

147 lines
5.2 KiB
PHP

<?php
use Laravel\Octane\Contracts\Operation;
use Laravel\Octane\Events\RequestHandled;
use Laravel\Octane\Events\RequestReceived;
use Laravel\Octane\Events\RequestTerminated;
use Laravel\Octane\Events\TaskReceived;
use Laravel\Octane\Events\TaskTerminated;
use Laravel\Octane\Events\TickReceived;
use Laravel\Octane\Events\TickTerminated;
use Laravel\Octane\Octane;
return [
/*
|--------------------------------------------------------------------------
| Octane Servers
|--------------------------------------------------------------------------
*/
'servers' => [
// RoadRunner via RPC socket
'roadrunner' => [
'rpc' => [
'tcp' => '127.0.0.1:7233',
],
'logs' => [
'mode' => env('OCTANE_LOGS_MODE', 'production' === env('APP_ENV') ? 'none' : 'dev'),
'level' => env('OCTANE_LOGS_LEVEL', 'info'),
],
'reload' => [
'watch' => env('OCTANE_RELOAD_WATCH', 'app,config,database,resources/views,routes'),
'interval' => env('OCTANE_RELOAD_INTERVAL', 2000),
],
'http2' => [
'enabled' => env('OCTANE_HTTP2_ENABLED', true),
],
'maxTotalWorkerMemory' => env('OCTANE_MAX_TOTAL_WORKER_MEMORY', 512), // MB — flush worker if exceeded
'worker' => [
'maxRequestCount' => env('OCTANE_WORKER_MAX_REQUEST_COUNT', 10000), // recycle to clear leaks
'maxMemoryMB' => env('OCTANE_WORKER_MAX_MEMORY_MB', 512),
],
],
// Swoole driver — recommended for WASL (best performance)
'swoole' => [
'mode' => env('OCTANE_MODE', 'SWOOLE_PROCESS'),
'options' => [
'log_file' => storage_path('logs/swoole.log'),
'package_max_length' => 8 * 1024 * 1024, // 8 MB
'worker_num' => env('OCTANE_WORKER_NUM', swoole_cpu_num()),
'task_worker_num' => env('OCTANE_TASK_WORKER_NUM', swoole_cpu_num()),
'max_request' => env('OCTANE_MAX_REQUEST', 10000),
'max_request_grace' => env('OCTANE_MAX_REQUEST_GRACE', 1000),
'max_request_execution_time' => env('OCTANE_MAX_REQUEST_EXECUTION_TIME', 30),
'reload_async' => true,
'enable_coroutine' => true,
'send_timeout' => 10,
],
'cache' => [
'rows' => env('OCTANE_CACHE_ROWS', 1000),
'bytes' => env('OCTANE_CACHE_BYTES', 10485760), // 10 MB per worker
],
'websocket' => [
'enabled' => env('OCTANE_WEBSOCKET_ENABLED', false),
],
'hot' => [
'enable' => env('OCTANE_HOT_RELOAD', 'local' === env('APP_ENV')),
'watch' => ['app', 'config', 'resources/views', 'routes'],
],
],
],
/*
|--------------------------------------------------------------------------
| Octane Cache Table
|--------------------------------------------------------------------------
*/
'cache' => [
'rows' => env('OCTANE_CACHE_ROWS', 1000),
],
/*
|--------------------------------------------------------------------------
| Octane Watchers / Listeners
| Flush state between requests to prevent leaks across requests in the
| long-running Octane process (critical for financial correctness).
|--------------------------------------------------------------------------
*/
'listeners' => [
RequestReceived::class => [
...Octane::prepareApplicationForNextOperation(),
...Octane::prepareApplicationForNextRequest(),
],
RequestHandled::class => [
//
],
RequestTerminated::class => [
// Clear request-scoped state between requests
],
TaskReceived::class => [
...Octane::prepareApplicationForNextOperation(),
],
TaskTerminated::class => [
//
],
TickReceived::class => [
...Octane::prepareApplicationForNextOperation(),
],
TickTerminated::class => [
//
],
Operation::class => [
// Octane::flushState(),
],
],
/*
|--------------------------------------------------------------------------
| Warm Specific Tags / Fifo
|--------------------------------------------------------------------------
*/
'warm' => [
...Octane::defaultServicesToWarm(),
'view' => fn ($app) => $app->make('view'),
],
/*
|--------------------------------------------------------------------------
| Garbage Collection Threshold (prevent memory leaks)
|--------------------------------------------------------------------------
*/
'garbage_collection_threshold' => env('OCTANE_GARBAGE_COLLECTION_THRESHOLD', 50),
/*
|--------------------------------------------------------------------------
| Maximum Execution Time (seconds) — financial ops should be fast
|--------------------------------------------------------------------------
*/
'max_execution_time' => env('OCTANE_MAX_EXECUTION_TIME', 30),
];