https://github.com/bitsbeats/php-softfailer
PHP library to suppress errors ("soft failures") unless they exceed a certain threshold within a given time interval.
https://github.com/bitsbeats/php-softfailer
Last synced: 3 months ago
JSON representation
PHP library to suppress errors ("soft failures") unless they exceed a certain threshold within a given time interval.
- Host: GitHub
- URL: https://github.com/bitsbeats/php-softfailer
- Owner: bitsbeats
- License: apache-2.0
- Created: 2019-08-15T09:26:17.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-15T14:19:40.000Z (almost 7 years ago)
- Last Synced: 2025-07-24T15:47:43.774Z (11 months ago)
- Language: PHP
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bitsbeats/php-softfailer
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](https://getcomposer.org/):
```
$> composer require bitsbeats/softfailer
```
## Usage
```php
$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.