nexus-actors / http-server-swoole
Nexus HTTP server — Swoole worker-mode adapter with WebSocket support.
Package info
github.com/nexus-actors/http-server-swoole
pkg:composer/nexus-actors/http-server-swoole
Requires
- php: >=8.5.7
- ext-swoole: >=6.2.1
- nexus-actors/core: ^0.1
- nexus-actors/http: ^0.1
- nexus-actors/http-ws: ^0.1
- nexus-actors/runtime: ^0.1
- nexus-actors/runtime-swoole: ^0.1
- nexus-actors/worker-pool: ^0.1
- nikic/fast-route: ^1.3
- nyholm/psr7: ^1.8
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/log: ^3.0
Requires (Dev)
- phpunit/phpunit: ^13.0
README
Worker-mode (Swoole process workers) HTTP+WebSocket runner. Implements nexus-http's HttpServerAdapter and ships SwooleWorkerServer::run() as the static entrypoint. The HTTP/WebSocket DSL lives in nexus-http-ws; this package is just the Swoole glue.
Install
composer require nexus-actors/http-server-swoole
Quickstart
use Monadial\Nexus\Core\Actor\ActorSystem; use Monadial\Nexus\Http\Response\Response; use Monadial\Nexus\Http\Server\Swoole\Server\SwooleWorkerConfig; use Monadial\Nexus\Http\Server\Swoole\Server\SwooleWorkerServer; use Monadial\Nexus\Http\Ws\CompiledApplication; use Monadial\Nexus\Http\Ws\WsApplication; SwooleWorkerServer::run( SwooleWorkerConfig::bind('0.0.0.0', 8080) ->workers(4) ->enableWebSocket(true), static function (ActorSystem $system): CompiledApplication { $app = WsApplication::create($system); $app->get('/health', static fn() => Response::ok('ok')); $app->ws('/ws/echo', EchoHandler::class); return $app->compile(); }, );
Each worker process gets its own ActorSystem + CompiledApplication. WebSocket events (Open/Message/Close) are only wired when the compiled app reports hasWebSocketRoutes() === true AND enableWebSocket(true) is set on the config.
Channel actors are worker-local — each worker has its own. Connections to the same channel landing on different workers see different actors.
Configuration
SwooleWorkerConfig::bind('0.0.0.0', 8080) ->workers(8) ->reactorThreads(2) ->maxRequest(10_000) ->maxConn(100_000) ->dispatchMode(2) ->shutdownTimeout(Duration::seconds(10)) ->enableWebSocket(true) ->installSignalHandlers(true) ->logger($psrLogger);
Architecture
- One
CompiledApplicationper worker, built atWorkerStartvia the user factory. - Restart-loop protection: 3 factory failures in 5s →
Server::shutdown(). - See
nexus-http-wsfor the DSL, handler/channel actor bases, and WS routing.
Status
Stable.
Repository
Read-only subtree split of nexus-actors/nexus. Report issues and send pull requests to the monorepo — this repository only receives automated pushes and release tags.