Download the PHP package narya/php-sdk without Composer
On this page you can find all versions of the php package narya/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download narya/php-sdk
More information about narya/php-sdk
Files in narya/php-sdk
Informations about the package php-sdk
Narya PHP SDK
PHP library that integrates PHP userland with the Narya Runtime Engine (Go).
Namespace: Narya\SDK.
Protocol: UDS (Unix Domain Sockets) + MessagePack, handshake NARYA1/OK, 4-byte BE length framing + payload.
Components
| Component | Description |
|---|---|
Worker (Runtime\Worker) |
Orchestrates the loop: receives request from Go, calls application or handler, sends response. Resets state between requests. |
WorkerBridge (Runtime\WorkerBridge) |
UDS + MessagePack bridge: handshake, read/write frames, invokes handler. |
| NaryaRequest / WorkerRequest | Request contract and implementation (id, method, uri, path, query, headers, body, remote_addr, host, scheme, timeout_ms, meta, worker_id, runtime_version). |
| NaryaResponse / WorkerResponse | Response contract and implementation (status, headers, body, error). The Bridge adds id and _meta. |
| ApplicationWorker | Application (framework) contract: handle(NaryaRequest): array|NaryaResponse and reset(). |
| LifecycleInterface / LifecycleManager | Worker lifecycle: boot() before the loop (e.g. connect to socket), shutdown() on exit (max_requests or EOF). Passed as Worker’s 4th argument or via setLifecycle(). |
Requirements
- PHP 8.2+
- msgpack extension (
pecl install msgpack) - Linux or WSL (UDS not supported on native Windows)
Installation
Basic usage
The Go runtime starts each process with: php worker.php --sock /path/to.sock.
With lifecycle (boot before the loop, shutdown on exit):
Example with a shared resource in the worker (e.g. connection opened in boot, closed in shutdown):
With a callable handler (no framework):
Dependency injection container
If your application already uses a DI container:
- boot() — Configure the container once when the worker starts (bindings, persistent connections).
- ApplicationWorker — Receive the container in the constructor and use it in
handle()to resolve services. - reset() — Here you clear the per-request context (ctx): request-scoped container state (e.g.
$container->resetRequestScope()). The Worker callsreset()after each request. - shutdown() — Cleanup when the worker exits (close connections, flush logs). Called once when leaving the loop.
So: clearing context on each request → inside reset(), not in shutdown. See a full example in examples/worker_with_container.php.
Tests
License
MIT
All versions of php-sdk with dependencies
ext-msgpack Version *