Search by

mini4work / webserver

MNaz

A PHP-only process-based application server

Package info

gitlab.com/mini4work/webserver

Issues

pkg:composer/mini4work/webserver

Statistics

Installs: 89

Dependents: 0

Suggesters: 0

Stars: 2

1.6.2 2026-11-25 21:36 UTC

README

Mini4Work Logo

Mini4Work is a PHP application server for HTTP/1.1, HTTP/2 and HTTP/3. It runs application handlers in worker processes and provides streaming requests and responses, TLS certificate management, worker rotation and endpoint limits.

Composer package: mini4work/webserver. First stable release: 1.0.0.

Mini4Work web server documentation

Requirements

  • PHP 8.3 or later on a supported Unix platform, with pcntl, posix and sockets.
  • OpenSSL for HTTPS and cURL for managed ACME certificates.
  • Enabled PHP FFI and libnghttp2 for HTTP/2.
  • A supported native QUIC backend for HTTP/3.

Use a maintained, patched PHP release. Plain HTTP/1.1 application requests can run without FFI or native protocol libraries. Manifest-based static file serving also works without FFI. Secure directory mode requires FFI.

Quick start

From your application's root, install the package and run the bundled server example.

composer require mini4work/webserver
php vendor/mini4work/webserver/examples/server.php

In another terminal, send a request to the running server.

curl http://127.0.0.1:8080/

The default is local HTTP/1.1 on 127.0.0.1:8080, without TLS. The server accepts one optional configuration file in JSON or JSONC format.

php vendor/mini4work/webserver/examples/server.php vendor/mini4work/webserver/config/auto.json
php vendor/mini4work/webserver/examples/server.php vendor/mini4work/webserver/config/full.jsonc

Profiles inherit the defaults in the commented full.jsonc. Configuration paths are relative to the selected file. See configuration.

Compression and static files

By default, Mini4Work negotiates Brotli or gzip for eligible buffered responses from 1 KiB through 1 MiB. If neither PHP encoder is installed, the server starts normally and sends the original response. Set compression.mode to off to disable dynamic compression. Response compression

To serve assets before Laravel Octane or another application handler, add their public directories to static.directories. Choose secure for live filesystem lookups, manifest for an immutable build, or precompressed for a build with Brotli or gzip copies. Static serving is disabled by default. Configuration and example manifests

Application handlers

Applications implement RequestHandlerInterface or use CallbackRequestHandler. Handlers receive an explicit request and return a response:

use M4W\WebServer\Cli\ServerCommand;
use M4W\WebServer\Http\CallbackRequestHandler;
use M4W\WebServer\Http\Request;
use M4W\WebServer\Http\Response;

require __DIR__.'/vendor/autoload.php';

$handler = new CallbackRequestHandler(
    static fn (Request $request): Response => Response::json([
        'method' => $request->method,
        'uri' => $request->uri,
    ])
);

exit((new ServerCommand)->run($argv ?? [__FILE__], $handler));

Read small bodies with an explicit limit, or stream larger bodies in chunks. Multipart forms and uploads are available through $request->multipart(). See the streaming API.

Workers are long-lived. Each managed request keeps its identity through lazy response reads and cleanup, including cancellation. Supported request globals and native session identity are scoped across managed request switches; see request state for the boundaries and session behavior. Use request-local application state. Blocking operations block their worker. This API does not emulate PHP's full per-request SAPI lifecycle. See framework integration. Laravel applications can use the Octane adapter.

Protocols and TLS

HTTP configurations
├── HTTP/1.1 — plain TCP
├── HTTP/1.1 + TLS
├── HTTP/2 + TLS — libnghttp2 (HPACK)
└── HTTP/3 + TLS — QUIC
    ├── quiche
    └── ngtcp2 + nghttp3

Automatic selection prefers HTTP/3, then HTTP/2, then HTTP/1.1 when their requirements are met. Explicit protocol selection requires its dependencies. TLS can use local development certificates, certificate files, or Let's Encrypt.

On PHP 8.6 with native polling enabled, each HTTP/3 transport reuses its socket watchers across requests. Existing deployments get this improvement when upgrading to 1.6.2. HTTP/3 benchmark

For HTTP/3 containers, publish both TCP and UDP. Configure the public UDP port when port mappings differ. Client HTTP/3 support and certificate trust are separate from the server's installed libraries.

Operations

Workers support bounded graceful shutdown and rotation. An optional local Unix socket provides status, worker restart and stop commands. In a copy of full.jsonc, set control.socket to @runtime/mini4work.sock and start the server with that file.

php examples/control.php @runtime/mini4work.sock status
php examples/control.php @runtime/mini4work.sock restart-workers

Set protection.endpoints to apply service-wide rate limits and per-worker concurrency limits to expensive routes.

See endpoint limits and capacity and overload.

Documentation

The documentation index covers configuration, application APIs, protocol installation and operational behavior. See Change Notes for release changes, fixes and known problems.

Tests

composer test
composer test:unit
composer test:security

The Docker compatibility matrix builds one image with PHP 8.3, 8.4, 8.5, and 8.6. It runs the standard suite (excluding the separate interop group) for each selected PHP version, then repeats it with tracing JIT on the first selected version (PHP 8.3 by default). The JIT run checks that JIT is active and passes the same INI configuration to PHP workers.

sh tests/Common/test-php-versions.sh
sh tests/Common/test-php-versions.sh 8.3

Tests are grouped under tests/Http1, tests/Http2, tests/Http3 and tests/Common. Shared infrastructure and scenarios covering multiple protocols belong to Common. Unit, integration, security and interoperability tests remain separate within each group. For example:

vendor/bin/pest --group=http2 --exclude-group=interop
vendor/bin/pest --group=http3 --exclude-group=interop

Tests require the project development dependencies and the native libraries for the protocols being exercised. Native callback regression fixtures also require a C compiler; the supplied validation Dockerfile includes one. A failing security regression is a release blocker; it must be investigated rather than skipped to obtain a passing result.

License

Mini4Work WebServer is available under the MIT License.