PHP code example of phpgt / async
1. Go to this page and download the library: Download phpgt/async library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpgt / async example snippets
$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();