gowork / throttler
Simple PHP execution throttler.
Installs: 7 918
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- phpstan/phpstan: ^0.12.3
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-29 06:05:40 UTC
README
Use the throttle to control the speed.
use GW\Throttler\Throttler; $throttler = new Throttler(1.0); foreach ($heavyTasks->all() as $task) { $throttler->throttle(); // wait a second... before next task $task->run(); }
Alternative usage for wrapping iterables:
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 }