Download the PHP package byfareska/swoole-server-bundle without Composer

On this page you can find all versions of the php package byfareska/swoole-server-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package swoole-server-bundle

byfareska/swoole-server-bundle

A long-running Swoole HTTP server for Symfony 8+ applications (PHP 8.5+).

Works like PHP-FPM: each worker is a separate process with its own Symfony kernel and handles one request at a time (enable_coroutine=false). Concurrency comes from the number of workers. Coroutines are disabled on purpose — a worker has a single kernel, i.e. one Doctrine connection and one identity map, so overlapping requests would share state (e.g. the PDO error "Cannot execute queries while other unbuffered queries are active").

Requirements

Installation

Registration in config/bundles.php (without Flex):

Configuration

The whole server is configured with a single DSN — preferably from an env var:

DSN format

Default server settings (overridable via the DSN):

option value why
enable_coroutine false requests within a worker are serialized — they share one kernel
http_compression false —
max_request 0 no worker recycling (long-lived connections)
package_max_length 64 MB the upload limit is enforced by Swoole, not PHP ini
output_buffer_size 64 MB Swoole's own default (2 MB) aborts larger buffered responses with a warning
log_level SWOOLE_LOG_INFO —

Usage

Health check

Set health_check_path (e.g. /healthz) to get a plain-text 200 ok answered directly by the server, before the kernel — it reports liveness of the server process and responds even while workers are still booting. Handy for docker/k8s health checks:

Metrics (Prometheus)

Long-running workers never get recycled (max_request=0), so a slow leak grows silently until the OOM killer restarts the process — and with N workers you cannot tell "one worker leaks" from "all of them grow" without per-process numbers. Enable metrics to get a Prometheus text endpoint answered directly by the server, before the kernel (like the health check):

How it works: every worker samples itself every sample_interval ms into a Swoole\Table (shared memory allocated by the master before the fork — no IPC), and whichever worker receives the scrape renders the whole table plus the server-wide counters. A worker that stops updating its row is stuck or dead — its last_sample_timestamp goes stale. The table outlives worker processes, which is what makes worker_restarts_total possible: a worker id whose row already exists on workerStart was re-forked (OOM kill, fatal error, recycling).

metric labels source
<ns>_worker_memory_rss_bytes / _hwm_bytes worker_id /proc/<pid>/status VmRSS / VmHWM (Linux only — omitted elsewhere)
<ns>_worker_php_memory_bytes / _peak_bytes worker_id memory_get_usage(true) / memory_get_peak_usage(true)
<ns>_worker_requests_total worker_id stats()['worker_request_count']
<ns>_worker_restarts_total worker_id re-forks of this worker id since server start
<ns>_worker_start_time_seconds, <ns>_worker_last_sample_timestamp_seconds worker_id worker clock
<ns>_process_memory_rss_bytes process=master\|manager /proc
<ns>_server_connections, _workers, _idle_workers, _requests_total, _accepted_total, _coroutines, _start_time_seconds — Swoole\Server::stats()
<ns>_php_memory_limit_bytes — ini_get('memory_limit') (omitted when -1)

Label cardinality is fixed (worker_id ∈ 0..N-1), so the series count does not grow with traffic. The endpoint has no authentication: expose the server port to your monitoring network only and do not route the path through the public reverse proxy. Scrape example:

Useful alerts: worker_memory_rss_bytes / php_memory_limit_bytes > 0.7, increase(worker_restarts_total[15m]) > 0, predict_linear(worker_memory_rss_bytes[2h], 6*3600) > php_memory_limit_bytes.

Behind a reverse proxy (trusted proxies)

The bridge builds the Request from raw Swoole data, so behind nginx/traefik the standard Symfony rules apply: without configured trusted proxies, Request::getClientIp() returns the proxy's IP and isSecure() is false even for TLS-terminated traffic. Configure it as usual:

Hot-reload (dev)

In debug mode a watcher (mtime polling — works also on Docker Desktop/macOS volumes, where inotify does not receive events from the host) scans watch_dirs and on any change stops the whole server ($server->stop()) — docker's/supervisor's restart policy brings up a fresh process, so the code is guaranteed to come up new. A graceful $server->reload() is deliberately not used: with 1 worker it does not work at all (ERRNO 507), and in debug a re-forked worker serves the old code anyway (class definitions sit in the master's memory after the DI container compilation).

Example for docker-compose:

Streaming (SSE / chunks)

A regular StreamedResponse with a callback returning a generator is supported. For full control over the chunks use ChunkYieldingStreamedResponse (or implement ChunkYieldingResponseInterface in your own response class):

The emitter reads chunks straight from the response (not through the callback), because HttpKernel wraps the callback with a wrapper that loses the returned generator.

A callback that echoes its output instead of returning an iterable (the classic FPM style) also works — the emitter captures the echo with an output buffer and rewrites it onto $res->write(). This is a fallback path: it costs an extra memory copy per chunk, loses logical chunk boundaries and logs a warning — prefer returning an iterable or ChunkYieldingResponseInterface.

File downloads

BinaryFileResponse is sent with Swoole's zero-copy sendfile() — the file never passes through PHP memory, so output_buffer_size does not apply to downloads. Range requests (206 Partial Content), X-Sendfile/ X-Accel-Redirect delegation, HEAD requests and deleteFileAfterSend() keep their standard Symfony semantics; responses backed by an in-memory SplTempFileObject fall back to a streamed copy.

What the bundle does for you

Extension points

interface / mechanism how to override
ErrorHandler\ExceptionResponseFactoryInterface alias to your service (e.g. JSON errors for an API)
Runtime\WorkerKernelFactoryInterface alias to your service (custom kernel boot, prewarming)
Bridge\SwooleRequestFactoryInterface alias to your service (custom Swoole→HttpFoundation request mapping)
Reset\WorkerResetterInterface escape hatch — prefer Symfony's ResetInterface (kernel.reset); implement this only for state it cannot reach
Bridge\Body\ResponseBodyEmitterInterface just implement it — autoconfiguration tags it into the body emission chain (first supports() wins, tag priority orders; built-ins: BinaryFile 100, ChunkYielding 50, Streamed 25, Content fallback -100)

Flex recipe

The repository ships a recipe under recipe/ (bundle registration, the config/packages/byfareska_swoole_server.yaml file and the SWOOLE_SERVER_DSN env entry). To have composer require apply it automatically, publish it on a private recipes endpoint (e.g. symfony/recipes-checker fork or a private Flex server) under byfareska/swoole-server-bundle/<version>/. Without Flex, follow the manual installation steps above.

Tests

The suite runs without ext-swoole — tests/Stub/ ships minimal stand-ins for Swoole\Http\Request/Response and the SWOOLE_LOG_* constants; with the extension loaded the real classes win. Static analysis runs at PHPStan level: max (Swoole symbols come from swoole/ide-helper).

Custom worker resetters

Prefer Symfony's standard mechanism first: implement Symfony\Contracts\Service\ResetInterface on the service that holds per-request state (autoconfiguration tags it with kernel.reset). The bundle runs services_resetter after every request, so such services are reset automatically — and the same code keeps working under FPM, in tests and with any other runtime.

Byfareska\SwooleServer\Reset\WorkerResetterInterface is an escape hatch for the cases ResetInterface cannot cover — e.g. state living outside the container (globals, static caches) or a reset that needs the kernel itself. Implement it and register the class as a regular service — autoconfiguration tags it with byfareska_swoole_server.worker_resetter and the bundle calls it after every request. Use the tag's priority to control ordering (higher runs first; the built-in services_resetter bridge runs at priority 100).

Structure

class responsibility
Command\ServerStartCommand Swoole server configuration and startup
Server\ServerDsn DSN parsing (host, port, workers, Swoole options)
Runtime\WorkerKernelFactoryInterface extension point: per-worker kernel boot
Runtime\WorkerKernelFactory default implementation: fresh kernel per worker (after fork)
Runtime\SwooleRequestHandler full request→kernel→response cycle + reset
Bridge\SwooleRequestFactoryInterface extension point: Swoole Request → HttpFoundation Request mapping
Bridge\SwooleRequestFactory default implementation of the request mapping
Bridge\SwooleResponseEmitter status/headers/cookies + delegation to the body emitter chain
Bridge\Body\ResponseBodyEmitterInterface extension point: body emission strategy per response kind
Bridge\Body\BinaryFileBodyEmitter files via zero-copy sendfile() (ranges, X-Sendfile, temp-file fallback)
Bridge\Body\ChunkYieldingBodyEmitter chunks read directly from ChunkYieldingResponseInterface
Bridge\Body\StreamedBodyEmitter StreamedResponse callbacks (iterable or echo via ob_ capture)
Bridge\Body\ContentBodyEmitter fallback: plain getContent()
ErrorHandler\ExceptionResponseFactoryInterface extension point: format of the outside-the-kernel error response
ErrorHandler\ExceptionResponseFactory default implementation: HTML 500 page
Profiler\ExceptionProfileCollector manual profile for the exception path
Reset\WorkerResetterInterface extension point: custom per-request resetters (tag byfareska_swoole_server.worker_resetter)
Reset\WorkerStateResetter composite running all tagged resetters after every request
Reset\SymfonyServicesResetter services_resetter bridge (the equivalent of $kernel->reset())
Reset\FormDataCollectorResetter workaround for the FormDataCollector leak (debug)
HotReload\HotReloadWatcher mtime polling + server stop on change
Metrics\ServerMetrics /metrics endpoint: table allocation before the fork, worker hooks, scrape response
Metrics\WorkerSampler per-worker timer writing the worker's own row (RSS, PHP memory, requests, restarts)
Metrics\WorkerMetricsTable Swoole\Table wrapper — one shared-memory row per worker id
Metrics\ProcessMemoryReader VmRSS/VmHWM from /proc/<pid>/status
Metrics\PrometheusTextRenderer snapshot → Prometheus text exposition (no client library)
HotReload\DirectoryFingerprint mtime+file-count fingerprint of the watched dirs

License

Released under the MIT License.


Made with ❤️ in Bydgoszcz 🇵🇱


All versions of swoole-server-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.5
ext-swoole Version *
psr/log Version ^3.0
symfony/config Version ^8.0
symfony/console Version ^8.0
symfony/dependency-injection Version ^8.0
symfony/error-handler Version ^8.0
symfony/http-foundation Version ^8.0
symfony/http-kernel Version ^8.0
symfony/service-contracts Version ^3.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package byfareska/swoole-server-bundle contains the following files

Loading the files please wait ...