gowork/throttler

简单的PHP执行节流器。

0.2 2020-12-04 11:40 UTC

This package is auto-updated.

Last update: 2024-08-29 05:30:48 UTC


README

Build Status

使用节流来控制速度。

use GW\Throttler\Throttler;

$throttler = new Throttler(1.0);

foreach ($heavyTasks->all() as $task) {
    $throttler->throttle(); // wait a second... before next task
    $task->run();
}

迭代器包装的替代用法

use GW\Throttler\Throttler;

$throttledTask = Throttler::iterable($heavyTasks->all(), 1.0);

foreach ($throttledTask as $task) {
    $task->run(); // for each iteration it will sleep one second
}