Skip to content

Configuration Reference ​

Leakless is configured via the TheMattos\Leakless\Config object in vanilla PHP, or via .env / config/leakless.php in Laravel Octane.


1. Vanilla PHP Configuration ​

Instantiate the Config object with your desired options:

php
use TheMattos\Leakless\DTOs\Config;

$config = new Config(
    maxDriftMb: 64,                     // Allowable memory drift above worker baseline (MB)
    maxRssMb: null,                     // Hard emergency ceiling (MB) for OOM prevention (optional)
    consecutiveViolationsThreshold: 5,  // Consecutive requests required before recycling
    recycleCooldownSeconds: 10,         // Minimum seconds between worker restarts (prevents restart storms)
    triggerGcOnBreach: true,            // Re-evaluate physical memory after gc_collect_cycles()
    driftJitterPercentage: 10,          // Random variation to desynchronize worker recycles
    maxRequests: 1000,                  // Ceiling on requests before worker recycling
    checkTransactions: true,            // Auto-rollback uncommitted PDO transactions
    checkFileDescriptors: false,        // Audit unclosed file handles (/proc/self/fd)
    autoRecycleOnViolation: true,       // Graceful worker recycling when breached
    logViolations: true,                // Emit warnings on anomalies
    resettables: [                      // Array of class-strings, objects, or callbacks to auto-reset
        App\Services\CartSession::class,
        fn () => LegacyRegistry::$cache = [],
    ],
    ztsAware: null,                     // Enable ZTS multithread attribution (null = auto-detect via PHP_ZTS)
    threadToleranceMb: 2.0,             // Minimum thread Zend memory growth (MB) to attribute process drift
    unattributedViolationsThreshold: 10,// Consecutive un-attributed breaches before recycling (native C leaks)
);

2. Environment Variables (.env) ​

In Laravel Octane environments, configure Leakless using .env variables:

ini
LEAKLESS_ENABLED=true
LEAKLESS_MAX_DRIFT_MB=64
LEAKLESS_MAX_RSS_MB=null
LEAKLESS_CONSECUTIVE_VIOLATIONS=5
LEAKLESS_RECYCLE_COOLDOWN=10
LEAKLESS_TRIGGER_GC=true
LEAKLESS_DRIFT_JITTER=10
LEAKLESS_MAX_REQUESTS=1000
LEAKLESS_CHECK_TRANSACTIONS=true
LEAKLESS_CHECK_FILE_DESCRIPTORS=false
LEAKLESS_AUTO_RECYCLE=true
LEAKLESS_LOG_VIOLATIONS=true
LEAKLESS_ZTS_AWARE=null
LEAKLESS_THREAD_TOLERANCE_MB=2.0
LEAKLESS_UNATTRIBUTED_THRESHOLD=10

Or publish config/leakless.php:

bash
php artisan vendor:publish --tag="leakless-config"

3. Configuration Reference Table ​

KeyEnvironment VariableDefaultDescription
enabledLEAKLESS_ENABLEDtrueMaster toggle to enable or disable Leakless audits.
max_drift_mbLEAKLESS_MAX_DRIFT_MB64Allowable relative RSS growth (in MB) above worker baseline before recycling evaluation.
max_rss_mbLEAKLESS_MAX_RSS_MBnullHard emergency physical RSS ceiling (MB) to prevent Linux OOM Killer SIGKILL.
consecutive_violationsLEAKLESS_CONSECUTIVE_VIOLATIONS5Hysteresis: consecutive post-GC breaches required before recycling worker.
recycle_cooldownLEAKLESS_RECYCLE_COOLDOWN10Cooldown window in seconds between worker recycles (prevents restart storms).
trigger_gcLEAKLESS_TRIGGER_GCtrueInvokes gc_collect_cycles() and re-reads /proc/self/statm on suspected breach.
drift_jitterLEAKLESS_DRIFT_JITTER10Percentage variation applied to max_drift_mb to desynchronize restarts across workers.
max_requestsLEAKLESS_MAX_REQUESTSnullMaximum request count per worker before triggering graceful recycling (null = unlimited).
check_transactionsLEAKLESS_CHECK_TRANSACTIONStrueAutomatically audits and rolls back open PDO transactions at request completion.
check_file_descriptorsLEAKLESS_CHECK_FILE_DESCRIPTORSfalseInspects /proc/self/fd for unclosed file handles and lingering network sockets.
auto_recycleLEAKLESS_AUTO_RECYCLEtrueAutomatically stops the worker when thresholds or persistent corruption are confirmed.
log_violationsLEAKLESS_LOG_VIOLATIONStrueEmits diagnostic logs when uncommitted transactions or state leaks are caught.
resettables—[]List of class-strings, objects, or callbacks to automatically reset at the end of each request.
zts_awareLEAKLESS_ZTS_AWAREnullEnable ZTS thread-safe memory attribution (null for auto-detect via PHP_ZTS).
thread_tolerance_mbLEAKLESS_THREAD_TOLERANCE_MB2.0Minimum Zend MM growth (MB) required to attribute process RSS drift to the active thread.
unattributed_violations_thresholdLEAKLESS_UNATTRIBUTED_THRESHOLD10Consecutive un-attributed RSS drift checks before recycling (protects against native C leaks).

Released under the MIT License.