bitsbeats / softfailer
库,用于抑制错误,除非它们在给定时间间隔内超过某个阈值
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 库用于抑制错误(“软错误”),除非它们在给定时间间隔内超过某个阈值。
功能
- 使用持久存储,因此失败计数包括独立的脚本调用或页面浏览
- 文件系统、memcache 和 APCu 存储驱动程序
安装
安装 SoftFailer 最简单的方法是使用 composer
$> composer require bitsbeats/softfailer
使用方法
$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); }
查看 example.php
获取完整示例。