Search by

phpgt / async

g105b

Promise-based non-blocking operations.

Package info

github.com/PhpGt/Async

Issues

pkg:composer/phpgt/async

Fund package maintenance!

PhpGt

Statistics

Installs: 4 262

Dependents: 4

Suggesters: 0

Stars: 0

v1.0.3 2026-05-04 16:34 UTC

This package is auto-updated.

Last update: 2026-08-25 12:03:13 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.

PHP.Gt/Async build status PHP.Gt/Async code quality PHP.Gt/Async code coverage PHP.Gt/Async latest release PHP.Gt/Async documentation

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();

Proudly sponsored by

JetBrains Open Source sponsorship program

JetBrains logo.