Download the PHP package qcodr/restate-sdk-php without Composer

On this page you can find all versions of the php package qcodr/restate-sdk-php. 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 restate-sdk-php

Restate PHP SDK

CI codecov Mutation testing badge Latest Stable Version Total Downloads PHP Version

A pure-PHP SDK for Restate — durable execution for Services, Virtual Objects, and Workflows. It mirrors the Rust SDK surface with idiomatic PHP: attributes for service definitions, a typed context API, and a true bidirectional HTTP/2 streaming server.

The Restate service protocol (v5–v7) is implemented from scratch in pure PHP — framing, protobuf messages, the journal/replay state machine, suspension, and signals — so the SDK has no native-extension dependency: the default server (AmpStreamingServer) runs on pure-PHP amphp/http-server, and a request/response Swoole server, a PSR-15 adapter, and an AWS Lambda handler are available as alternative transports.

Features

Requirements

Installation

Quick start

Define services with attributes; the first parameter is always the context.

Serve them over true bidirectional HTTP/2 streaming (the default server):

Register the deployment with a running Restate server, then invoke through the ingress:

Drop ->protocolMode(ProtocolMode::BidiStream) (and add --use-http1.1 when registering) to serve plain request/response over the same amphp host, or swap in SwooleServer / the PSR-15 / Lambda adapters — see Transports below.

Workflows & durable promises

Context API

Service classes must be stateless. A bound service instance is shared across concurrent invocations within the server process — keep per-invocation data in local variables or Restate state ($ctx->set(...)), never in mutable instance properties.

Capability Methods
Side effects run(name, fn, ?RunOptions) — with optional per-run RetryPolicy
Timers sleep(seconds), timer(seconds) → DurableFuture
Calls (await) serviceCall, objectCall, workflowCall (+ idempotencyKey, headers)
Calls (async) serviceCallAsync, objectCallAsync, workflowCallAsync → DurableFuture
Calls (handle) serviceCallHandle, … → CallHandle (result(), invocationId())
One-way sends serviceSend, objectSend, workflowSend (optional delay)
Cancellation cancel(invocationId) — peer cancel; observed as CancelledException (409)
Combinators select, awaitAll, awaitAny (any), awaitAllSucceeded (all-or-fail)
Tracing traceContext() — W3C trace context (bridge to OpenTelemetry)
Awakeables awakeable(), resolveAwakeable, rejectAwakeable
State (objects) get, set, clear, clearAll, stateKeys
Promises (wf) promise, peekPromise, resolvePromise, rejectPromise
Request meta key(), invocationId(), requestHeaders(), requestIdempotencyKey()
Randomness random()->uuidV4(), randomInt, randomFloat
Logging logger() — a replay-aware PSR-3 logger

Errors: throw TerminalException for a non-retryable failure returned to the caller; RetryableException (optionally pause: true or a retryDelayMillis) for a tuned transient failure; any other throwable is a plain transient error (retried).

Logging & tracing

ctx->logger() returns a PSR-3 logger that suppresses records emitted during replay, so each line is logged exactly once even though handlers re-run from the top on every slice. Provide the underlying logger (e.g. Monolog) when constructing the server: new AmpStreamingServer($endpoint, logger: $myLogger) (defaults to a null logger).

For distributed tracing, mind the propagation boundary:

The SDK stays dependency-free and emits no spans itself. Install open-telemetry/sdk and use the withIncomingTraceParent() bridge in examples/tracing.php to start spans under the incoming trace.

Production configuration

Discovery options. Configure per-service / per-handler behavior the runtime reads from the manifest (negotiated up to schema v4):

Request identity verification (opt-in; requires ext-sodium). Reject requests not signed by your Restate instance's key:

Transports. The default AmpStreamingServer (pure-PHP amphp) serves true bidirectional HTTP/2 streaming. One amphp process is a single event loop; pass a worker count to pre-fork N processes that share the port via SO_REUSEPORT (needs ext-pcntl) and scale across cores like a Swoole worker pool:

Its connection, concurrency and idle ceilings default to values sized for the Restate runtime as the only peer — many long-lived, deliberately idle streams from one IP, which amphp's own defaults reject. That is not a general hardening posture: if the endpoint is reachable by anything other than your runtime (especially without identityKey()), tighten them:

The same framework-agnostic core is also hostable request/response via the Swoole server (Qcodr\Restate\Sdk\Server\SwooleServer, needs ext-swoole), a PSR-15 adapter (Qcodr\Restate\Sdk\Server\Psr15Handler) in any Slim/Mezzio stack, on AWS Lambda (Qcodr\Restate\Sdk\Server\LambdaHandler — Function URL / API Gateway proxy), and directly via RequestProcessor (bytes in → bytes out).

Typed clients. bin/restate-codegen <ServiceClass> [outDir] [namespace] generates an IDE-autocompletable client so callers write GreeterClient::fromContext($ctx)->greet('world') instead of stringly-typed $ctx->serviceCall('Greeter','greet','world'). The discovery manifest also carries a JSON Schema for each handler's input/output, derived from the PHP types.

Serde. JSON is the default; BytesSerde provides raw octet-stream passthrough. Inject a custom Serde into the server/processor for other formats.

Examples

The examples/ directory ports the Rust SDK's examples to PHP. Each file is a self-contained, runnable endpoint.

Example Shows
greeter.php the simplest stateless service
counter.php Virtual Object state (get / add / increment / reset)
run.php durable side effects (ctx->run) around an HTTP call
failures.php terminal (no-retry) vs transient (retried) errors
fan_out.php concurrent durable timers via timer() + select()
schema.php structured JSON input/output + scalars
cron.php a periodic task that re-schedules itself with delayed sends
services.php the canonical Service + Virtual Object + Workflow trio
tracing.php replay-aware PSR-3 logging (run standalone: php examples/tracing.php)

Run a single example with the bundled server (amphp; the per-example endpoints are request/response, so --use-http1.1 is fine):

Or bring all of them up live (Docker) over true bidi HTTP/2, against a real runtime:

Testing

Unit tests run anywhere (no extensions, no Docker):

End-to-end verification is the official cross-SDK conformance suite (restatedev/e2e) — the same battery every Restate SDK runs. It boots a real Restate runtime + a PHP image of the standard test-services and drives them (needs JDK ≥ 21 + an AVX2 host):

The default config passes 48 / 49 over the bidi (amphp) transport on a V7-enabled runtime — Cancellation 6/6, KillInvocation 1/1, Signals 2/2 included. It also runs in CI (conformance.yml); an AVX2-free offline fallback is documented in conformance/README.md.

To try the example services live by hand:

Code quality

The project ships a strict static-analysis, coding-standard, and security gate — all of it runs fully offline (no cloud/SaaS):

The Compose file pins restatedev/restate:1.5.2 (the last AVX2-free image, so it runs on older hardware); it already serves the bidi examples. Override with RESTATE_IMAGE=... for a newer runtime — V7 cancellation/signals over bidi needs ≥ 1.7 (which needs AVX2), as covered in conformance/README.md.

Architecture

The framework-agnostic RequestProcessor (bytes in → bytes out) is the testable core; each server is one swappable transport. The default AmpStreamingServer advertises BIDI_STREAM: the runtime keeps the invocation channel open in both directions, streaming the journal and late completions/signals, so a parked await is resumed on the next result instead of writing a suspension. The request/response transports (SwooleServer, PSR-15, Lambda) advertise REQUEST_RESPONSE instead: the SDK processes one slice and suspends when it awaits a result it does not yet have, and the runtime re-invokes with a longer journal so the handler replays from the top.

License

Apache-2.0


All versions of restate-sdk-php with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-json Version *
ext-mbstring Version *
psr/http-factory Version ^1
psr/http-message Version ^2
psr/http-server-handler Version ^1
psr/log Version ^3.0
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 qcodr/restate-sdk-php contains the following files

Loading the files please wait ...