bitsbeats / softfailer
Library to suppress errors unless they exceed a certain threshold within a given time interval
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/bitsbeats/softfailer
Requires
- php: >=7.2
- ext-json: *
- ramsey/uuid: ^3.8
- symfony/yaml: ^4.3
Requires (Dev)
- phpunit/phpunit: ^8.3
Suggests
- ext-apcu: Required for using the APCu storage driver
- ext-memcached: Required for using the Memcached storage driver
This package is auto-updated.
Last update: 2025-09-16 04:22:02 UTC
README
PHP library to suppress errors ("soft failures") unless they exceed a certain threshold within a given time interval.
Features
- uses persistent storage, so that failures are counted among independent script calls or pageviews
- storage drivers for filesystem, memcache and APCu
Install
The easiest way to install SoftFailer is by using composer:
$> composer require bitsbeats/softfailer
Usage
$storage = new Filesystem('/tmp/softfail.txt', 500); // hard fail if 3 or more "soft fails" occur within a 3600 second time window $sf = new SoftFailer($storage, 3, 3600); try { $sf->recordFailure(new DateTime()); } catch (HardFailLimitReachedException $e) { // a "hard fail" is triggered by throwing a "HardFailLimitReachedException" exception print "FAIL: {$e->getMessage()}\n"; $sf->clearFailPoints(); exit(1); }
See example.php
for the full example.