phpgt / async
Promise-based non-blocking operations.
Fund package maintenance!
v1.0.1
2025-03-07 17:26 UTC
Requires
- php: >=8.1
- ext-dom: *
- phpgt/promise: ^2.0
Requires (Dev)
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.1
- squizlabs/php_codesniffer: ^3.7
- dev-master
- v1.0.1
- v1.0.0
- v0.1.0
- dev-dependabot/composer/phpstan/phpstan-2.1.41
- dev-3-event-model
- dev-dependabot/composer/phpstan/phpstan-2.1.40
- dev-dependabot/composer/squizlabs/php_codesniffer-4.0.1
- dev-add-jetbrains-sponsorship
- dev-ci-2025-sec
- dev-dependabot/composer/phpunit/phpunit-9.6.5
- dev-event
- dev-global
This package is auto-updated.
Last update: 2026-03-17 09:37:27 UTC
README
To be able to run asynchronous code in PHP, a loop needs to run in the background to observe and dispatch events, and handle the resolution of promises.
This repository provides the concepts of a Loop, different Timer implementations and a publish-subscribe model for Event objects.
Example usage
A loop with three individual timers at 1 second, 5 seconds and 10 seconds.
$timeAtScriptStart = microtime(true); $timer = new IndividualTimer(); $timer->addTriggerTime($timeAtScriptStart + 1); $timer->addTriggerTime($timeAtScriptStart + 5); $timer->addTriggerTime($timeAtScriptStart + 10); $timer->addCallback(function() use($timeAtScriptStart) { $now = microtime(true); $secondsPassed = round($now - $timeAtScriptStart); echo "Number of seconds passed: $secondsPassed", PHP_EOL; }); $loop = new Loop(); $loop->addTimer($timer); echo "Starting...", PHP_EOL; $loop->run();