bitsbeats / softfailer
Library to suppress errors unless they exceed a certain threshold within a given time interval
v1.0.1
2019-08-15 14:17 UTC
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: 2024-09-16 01:58:24 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.