Download the PHP package phpdot/server-swoole without Composer
On this page you can find all versions of the php package phpdot/server-swoole. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package server-swoole
phpdot/server-swoole
Swoole HTTP/WebSocket server adapter for PSR-15. Framework-agnostic, standalone, full Swoole coverage.
Install
Requires ext-swoole >= 6.0 and PHP 8.3+.
Quick Start
$handler is any PSR-15 RequestHandlerInterface -- your router, your framework, your middleware pipeline.
Server Configuration
ServerConfig is a simple readonly data class. No static methods, no builders -- just named constructor parameters:
Workers & Process
SSL / HTTPS
Static Files
Static file requests bypass PHP entirely -- served directly by Swoole's kernel.
Compression
Raw Swoole Settings
For any Swoole setting not covered by typed properties:
Typed properties always take precedence over rawSettings.
Inside the phpdot framework
ServerConfig carries #[Config('server')], so when used with phpdot/package it's auto-hydrated from config/server.php:
The container resolves ServerConfig automatically — no manual new ServerConfig(...) needed when running inside the framework. Standalone consumers (no phpdot/package) instantiate ServerConfig directly via the constructor as shown above.
SwooleServer itself isn't auto-wired (its constructor uses an intersection type for the PSR-17 factory, which PHP-DI can't autowire). Register it manually in your application boot:
For per-coroutine scoping of Scope::SCOPED services (the standard pattern under Swoole), install phpdot/container-swoole and register its provider:
Event Callbacks
Register callbacks directly on the server. Multiple callbacks per event -- they stack, never replace:
Available Events
| Category | Events |
|---|---|
| Lifecycle | onStart, onManagerStart, onManagerStop, onWorkerStart, onWorkerStop, onWorkerExit, onWorkerError, onBeforeShutdown, onShutdown, onBeforeReload, onAfterReload |
| Connection | onConnect, onClose |
| Task | onTask, onFinish |
| IPC | onPipeMessage |
| WebSocket | onOpen, onMessage, onHandshake, onDisconnect |
WebSocket
When any WebSocket callback is registered, the server automatically creates a WebSocket\Server instead of Http\Server. HTTP and WebSocket work on the same port:
Active WebSocket Methods
Push messages and manage connections from anywhere in your application:
Task Workers
Offload heavy work to task worker processes:
Timers
Set recurring or one-shot timers:
Connection Management
Server Info & Lifecycle
Escape Hatch
For advanced Swoole features not directly exposed (addProcess, addListener, bind, protect, etc.):
Streaming (CallbackStreamInterface)
For real-time streaming (SSE, chunked responses), implement CallbackStreamInterface:
The ResponseConverter detects this interface and streams each chunk directly via $swooleResponse->write() -- data reaches the client immediately without buffering.
Architecture
Response Emission Strategies
The ResponseConverter selects the optimal strategy for each response:
| Strategy | When | How |
|---|---|---|
| CallbackStream | Body implements CallbackStreamInterface |
write() per chunk -- true streaming |
| Sendfile | Body is a plain file stream | sendfile() -- zero-copy kernel transfer |
| Empty | Body size is 0 | end() -- no body |
| Chunked | Body exceeds chunk threshold (default 1 MB) | write() in chunks |
| Direct | Everything else | end($body) -- single write |
Production Example
Package Structure
PSR Standards
| PSR | Usage |
|---|---|
| PSR-7 | ServerRequestInterface, ResponseInterface -- the bridge format |
| PSR-15 | RequestHandlerInterface -- your application entry point |
| PSR-17 | All 4 factories -- builds PSR-7 objects from Swoole data |
Development
License
MIT
All versions of server-swoole with dependencies
ext-swoole Version >=6.0
psr/http-message Version ^2.0
psr/http-factory Version ^1.0
phpdot/contracts Version ^1.8
psr/http-server-handler Version ^1.0