spiral / rapira-bridge
Rapira application server integration for Spiral Framework
Fund package maintenance!
Requires
- php: >=8.4
- psr/http-factory: ^1.1
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.0 || ^2.0
- psr/http-message-implementation: ^1.0
- rapira/contract: ^0.10
- rapira/http: ^0.1.7
- spiral/framework: ^3.15.6
Requires (Dev)
- ext-curl: *
- bamarni/composer-bin-plugin: ^1.8
- internal/dload: ^1.18
- llm/skills: ^1.23
- nyholm/psr7: ^1.8.2
- rapira/testing: ^0.1.9
- roxblnfk/unpoly: ^1.8
- spiral/dumper: ^3.3
- spiral/nyholm-bridge: ^1.3
- testo/testo: ^0.10.62
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-05 16:34:37 UTC
README
Rapira application server integration for Spiral Framework
Runs a Spiral application under Rapira, the PHP application server written in Rust.
The bridge serves HTTP in Rapira's dispatcher mode: one long-lived PHP process takes request/response exchanges from the host, runs each through the Spiral HTTP pipeline and writes the response back.
Get Started
Installation
composer require spiral/rapira-bridge
The bridge needs Spiral Framework 3.15.6+ and a PSR-7 and PSR-17 implementation, e.g.
spiral/nyholm-bridge.
Usage
Add the HTTP bootloader to the application kernel:
use Spiral\RapiraBridge\Bootloader as RapiraBridge; class Kernel extends \Spiral\Framework\Kernel { protected const LOAD = [ // ... RapiraBridge\HttpBootloader::class, ]; }
The entry script is the usual Spiral one; the kernel picks the dispatcher from the mode the host launched the process in:
// app.php use App\Application\Kernel; require __DIR__ . '/vendor/autoload.php'; Kernel::create(directories: ['root' => __DIR__])->run()?->serve();
Point the Rapira pool at it in dispatcher mode:
# rapira.toml [http] listen = "0.0.0.0:8080" [http.pool] entrypoint = "app.php" mode = "dispatcher"
rapira serve
What the bridge does
RapiraBootloaderexposes the runtime to the container:Rapira\Mode,Rapira\DispatcherandRapira\Http\HttpDispatcher. When the pool hands the process a dispatcher no bootloader serves, it fails with a hint which bootloader is missing.HttpBootloaderregisters the HTTP dispatcher. It hydrates a PSR-7 request from each exchange withrapira/http, runs it throughSpiral\Http\Httpand writes the response into the exchange: a small body in one write, a large one streamed in chunks.- Requests are served one at a time, and the application is finalized after each of them.
- A failure in the handler, or in the response body before the head went out, is reported to the exception
handler and answered with
500— with the error details outside the production environment. A failure after the head went out leaves the response unfinished, and the host breaks the connection. - A response to
HEADdeclares the length of the body aGETwould get, without sending it — when the body knows its size or the application declaredContent-Length.
Limitations
- Only the dispatcher mode is served. The worker mode is reported as unsupported; the classic mode is a plain SAPI request and is left to other dispatchers.
- The kernel serves with the first dispatcher that accepts the process. Under Rapira
PHP_SAPIis notcli, so a SAPI dispatcher (spiral/sapi-bridge) loaded beforeHttpBootloadertakes the process over: keep it after, or out of a kernel that runs under Rapira.
Testing
composer test # all suites, the acceptance one included composer test:unit composer test:feature # the application against a scripted Rapira runtime composer test:acceptance # the application under the real `rapira` binary, downloaded on demand
Static analysis, mutation testing and code style run from isolated installs in vendor-bin:
composer bin all install composer psalm composer infect composer cs:fix