Zero-State & Memory Leak Prevention for PHP Persistent Workers (FrankenPHP & Laravel Octane)
In traditional PHP-FPM, worker processes terminate after each request, allowing the OS to wipe memory and state. Persistent runtimes like FrankenPHP Worker Mode and Laravel Octane keep PHP in memory across thousands of requests. While significantly faster, persistent workers can suffer from unmonitored C-extension memory growth, dangling database transactions, and polluted global state.
Leakless is an autonomous guardian for persistent PHP: it reads real Linux kernel RSS from /proc/self/statm, rolls back uncommitted PDO transactions, cleans runtime state in finally blocks, and provides static analysis via PHPStan and Pest assertions.
# Runtime engine (production)
composer require themattosdev/leakless
# Developer tooling, CLI analyzer, and Pest assertions
composer require --dev themattosdev/leakless-devuse TheMattos\Leakless\Config;
use TheMattos\Leakless\Integrations\FrankenPhp\FrankenPhp;
$config = new Config(maxRssMb: 256, maxRequests: 1000);
FrankenPhp::run(function () {
echo json_encode(['status' => 'ok', 'timestamp' => time()]);
}, $config);Leakless automatically registers into Laravel Octane via package auto-discovery. Configure parameters in .env:
LEAKLESS_MAX_RSS_MB=256
LEAKLESS_MAX_REQUESTS=1000
LEAKLESS_CHECK_TRANSACTIONS=true
LEAKLESS_LOG_VIOLATIONS=truetest('services are worker safe and execute cleanly', function () {
expect(PaymentService::class)->toBeLeakless();
expect(function () {
(new OrderProcessor())->handle();
})->toRunCleanly(maxDriftMb: 5.0);
});vendor/bin/leakless analyzeFull documentation, architecture guides, kernel memory details, and anti-pattern catalogues are available at:
👉 https://leakless.themattos.dev
# Run test suite
docker compose run --rm app vendor/bin/pest
# Code style
docker compose run --rm app vendor/bin/pint --test
# Static analysis (Level 9)
docker compose run --rm app composer analyseOpen-source software licensed under the MIT License.
Developed by Jonathan Gonçalves.
