Download the PHP package mj-zana/idempotency without Composer
On this page you can find all versions of the php package mj-zana/idempotency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download mj-zana/idempotency
More information about mj-zana/idempotency
Files in mj-zana/idempotency
Download mj-zana/idempotency
More information about mj-zana/idempotency
Files in mj-zana/idempotency
Vendor mj-zana
Package idempotency
Short Description Idempotency keys for Zana HTTP routes: a retried request gets the stored response instead of running twice
License MIT
Package idempotency
Short Description Idempotency keys for Zana HTTP routes: a retried request gets the stored response instead of running twice
License MIT
Please rate this library. Is it a good library?
Informations about the package idempotency
Zana Idempotency
Idempotency keys for Zana HTTP routes. A client sends an Idempotency-Key
header with a request that must not run twice, such as "pay". The first
request runs and its response is stored. A retry with the same key gets
that response again instead of paying twice. Requires PHP 8.5 or later.
Marking a route
Mark the handler with #[Idempotent], and run IdempotencyMiddleware on
its route:
required: truerefuses a request without a key (400). By default, a request without a key runs unprotected.ttlkeeps the key for that many seconds. The default isidempotency.ttl, a day.- The middleware only acts on
#[Idempotent]handlers, so it can run on a whole group of routes.
What a client gets
| Request | Response |
|---|---|
| A new key | The handler runs; its response is stored |
| The same key and the same request | The stored response, with Idempotent-Replayed: true |
| The same key while the first request still runs | 409, with Retry-After: 1 |
| The same key with another method, path, query or body | 422 |
| A key that is not 1 to 255 visible ASCII characters | 400 |
- Atomic: a key is claimed with one database insert, so of two simultaneous requests exactly one runs, across processes and servers.
- Failures free the key: a response of 500 or more, or an exception, is not stored, so the client can retry. A 4xx response is an answer and is replayed.
- Stopped requests: a request that stops without an answer holds its key
for
idempotency.lock_seconds; a retry after that runs it again. - Per user: with
mj-zana/security, keys belong to the signed-in user, so two users never share one. Without a signed-in user, keys are shared, so clients must generate unique keys (a UUID).
Configuration
Register IdempotencyServiceProvider with HttpServiceProvider and
DatabaseServiceProvider. Create the table, and delete expired keys daily:
Check and inspect
check: reports an error when the keys table cannot be read. It warns about an#[Idempotent]handler whose route does not run the middleware (withmj-zana/routing).inspect idempotency: shows the stored, running and expired keys.
License
MIT
All versions of idempotency with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.5
mj-zana/core Version ^2.11
mj-zana/database Version ^2.12
mj-zana/http Version ^2.10
psr/http-factory Version ^1.1
psr/http-message Version ^2.0
psr/http-server-middleware Version ^1.0
mj-zana/core Version ^2.11
mj-zana/database Version ^2.12
mj-zana/http Version ^2.10
psr/http-factory Version ^1.1
psr/http-message Version ^2.0
psr/http-server-middleware Version ^1.0
The package mj-zana/idempotency contains the following files
Loading the files please wait ...