Download the PHP package rasuvaeff/yii3-idempotency-db without Composer
On this page you can find all versions of the php package rasuvaeff/yii3-idempotency-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rasuvaeff/yii3-idempotency-db
More information about rasuvaeff/yii3-idempotency-db
Files in rasuvaeff/yii3-idempotency-db
Package yii3-idempotency-db
Short Description Database-backed idempotency storage for Yii3 APIs
License BSD-3-Clause
Homepage https://github.com/rasuvaeff/yii3-idempotency-db
Informations about the package yii3-idempotency-db
rasuvaeff/yii3-idempotency-db
Database-backed idempotency storage for Yii3 APIs. Implements
IdempotencyStorage from rasuvaeff/yii3-idempotency with atomic claim
via INSERT (unique PK), response replay, and TTL-based expiration.
Using an AI coding assistant? llms.txt contains a compact API reference you can paste into your prompt.
Requirements
- PHP 8.3+
rasuvaeff/yii3-idempotency^1.0yiisoft/db^2.0yiisoft/db-migration^2.0psr/clock^1.0
Installation
Usage
Basic setup
Run migration
Or use the migration class directly:
Table schema
| Column | Type | Description |
|---|---|---|
key |
VARCHAR(255) PK |
Idempotency key value |
fingerprint |
VARCHAR(64) |
SHA-256 hash of method + path + query + body |
status_code |
SMALLINT |
HTTP response status code |
headers |
TEXT |
JSON-encoded response headers (array<string, list<string>>) |
body |
TEXT |
Response body |
expires_at |
VARCHAR(30) |
Expiration timestamp (UTC, Y-m-d H:i:s) |
claimed |
BOOLEAN |
Whether the key is claimed (in-progress) |
Yii3 integration
The package provides config/di.php and config/params.php for yiisoft/config.
Default params:
DI wiring binds IdempotencyStorage::class to DbIdempotencyStorage.
How it works
- Claim:
INSERTwith unique PK onkeyandexpires_at = now + claimTtlSeconds. If the insert succeeds, the key is claimed atomically. A duplicate key raises a DB integrity error, whichclaim()converts tofalse; any other DB error propagates. - Store: After the handler completes, the response is upserted into the row
and
claimedis set to0;expires_atbecomes the record TTL deadline. - Load: On a subsequent request with the same key,
load()reads the row. An active claim (claimed = 1, deadline not reached) returnsnullwithout deleting the row — the middleware then fails its ownclaim()and responds 409. A stale claim (deadline passed — crashed process) is deleted and may be re-claimed. A completed record is rehydrated viaIdempotencyRecord::restore()and checked against its TTL; expired records are deleted. - Release: If the handler throws (or returns 5xx),
release()deletes the claim row. - Cleanup:
deleteExpired()removes all rows pastexpires_at(uses theidx_idempotency_expires_atindex) — call it from a cron task.
Security
- Idempotency keys are validated by core (
IdempotencyKey). - Fingerprints are SHA-256 hashes — no raw user input stored beyond the key.
- Response bodies are stored as-is; avoid storing sensitive data without encryption at the application layer.
- All timestamps are stored in UTC — storage behavior does not depend on the PHP default timezone.
Examples
See examples/ for runnable scripts.
Development
License
BSD-3-Clause. See LICENSE.md.
All versions of yii3-idempotency-db with dependencies
psr/clock Version ^1.0
rasuvaeff/yii3-idempotency Version ^1.0
yiisoft/db Version ^2.0
yiisoft/db-migration Version ^2.0