kislayphp / persistence
Request-safe persistence runtime for KislayPHP (transaction guard + bounded cache)
Package info
github.com/KislayPHP/persistence
Language:C++
Type:php-ext
Ext name:ext-kislayphp_persistence
pkg:composer/kislayphp/persistence
0.0.1
2026-03-01 08:26 UTC
Requires
- php: >=8.2
- kislayphp/core: >=0.0.3
Provides
This package is not auto-updated.
Last update: 2026-03-03 13:45:56 UTC
README
Request-safe persistence runtime for long-lived KislayPHP servers.
Concurrency Mode
- Default API mode is synchronous.
- Database and transaction operations are request-scoped and deterministic by design.
- This module should remain sync-first; async behavior belongs in core/gateway/eventbus and async HTTP clients.
Why this extension
Persistent servers keep PHP objects alive across requests. This extension hardens two common failure modes:
- Unclosed DB transactions leaking between requests
- Unbounded static in-memory caches
It is designed to be attached once to Kislay\Core\App; after that, cleanup is automatic on each request.
Install
pie install kislayphp/persistence:0.0.1
Add to php.ini:
extension=kislayphp_persistence.so
Usage (C++ facades)
<?php $app = new Kislay\Core\App(); $config = require __DIR__ . '/config/app.php'; Kislay\Persistence\DB::boot($config['database']); Kislay\Persistence\DB::attach($app); $app->post('/users', function ($req, $res) { $user = Kislay\Persistence\DB::transaction(function (PDO $db) use ($req) { $payload = $req->getJson() ?? []; $stmt = $db->prepare('INSERT INTO users(name,email) VALUES(:name,:email)'); $stmt->execute([ ':name' => $payload['name'] ?? 'unknown', ':email' => $payload['email'] ?? 'unknown@example.com', ]); return [ 'id' => (int) $db->lastInsertId(), 'name' => $payload['name'] ?? 'unknown' ]; }); $res->json($user, 201); });
API
Kislay\Persistence\DB:
boot(array $databaseConfig): boolconnection(?string $name = null): PDOconnect(?string $name = null): PDOtransaction(callable $callback, ?string $connection = null): mixedattach(Kislay\Core\App $app): boolcleanup(): int
Kislay\Persistence\Eloquent:
boot(array $databaseConfig): boolconnection(?string $name = null): PDOtransaction(callable $callback, ?string $connection = null): mixedattach(Kislay\Core\App $app): bool
Kislay\Persistence\Runtime:
attach(Kislay\Core\App $app): booltrack(object $pdo): booltransaction(object $pdo, callable $callback): mixedbeginRequest(): voidcleanup(): intcachePut(string $pool, string $key, mixed $value, ?int $ttlSeconds = null): boolcacheGet(string $pool, string $key, mixed $default = null): mixedcacheForget(string $pool, string $key): boolcacheClear(?string $pool = null): intsetCacheLimits(int $maxEntriesPerPool, int $defaultTtlSeconds): bool
Notes
- Cache is in-process memory; use Redis/Memcached for distributed cache.
attach()requires Core versions that exposeonRequestStartandonRequestEnd.DB::boot()expects Laravel-style config shape:default+connections.