graceas/php-retry
Composer 安装命令:
composer require graceas/php-retry
包简介
A library for retrying actions that can fail.
关键字:
README 文档
README
A library for retrying actions that can fail.
Installation
Through composer:
"require": {
...
"graceas/php-retry": "v0.0.3"
...
}
Usage (general example)
$retry = new Retry();
$i = 0;
$retry->retry(
new RetryAction(
// can pass any action that can fail (database query, curl loading, etc)
function() use (&$i) {
// simulate non-periodic error (eg broken database connection)
$i++;
return ($i > 3) ? $i : 1 / 0;
},
4 // expect 4 as result for callable function
),
new LinearRetryStrategy(10 /* timeout ms */, 5 /* retrying times */)
);
if ($retry->isSuccess()) {
// task success
} else {
// task failed
// echo $retry->getLog();
}
Example Output
echo $retry->getLog();
> 1577074792: [1 of 5] [sleep 10] Division by zero in /Users/gorelov/projects/php-retry/tests/RetryTest.php on line 52
> 1577074792: [2 of 5] [sleep 10] Division by zero in /Users/gorelov/projects/php-retry/tests/RetryTest.php on line 52
> 1577074792: [3 of 5] [sleep 10] Division by zero in /Users/gorelov/projects/php-retry/tests/RetryTest.php on line 52
> 1577074977: [4 of 5] [sleep 10] success
Backoff Strategies
LinearRetryStrategy - Each attempt waits a configured time.
ExponentialRetryStrategy - The base delay time is calculated as: time ^ attempt where attempt is the number of unsuccessful attempts that have been made.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-22