PHP code example of zwirek / react-timer-handler
1. Go to this page and download the library: Download zwirek/react-timer-handler 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/ */
zwirek / react-timer-handler example snippets
$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);
$success = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
echo 'example_timer', PHP_EOL;
});
var_dump($success); //prints true
$loop->run();
echo 'done', PHP_EOL;
$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);
$first = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
echo 'first', PHP_EOL;
});
$second = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
echo 'second', PHP_EOL;
});
var_dump($first); //prints true
var_dump($second); //prints false
$loop->run();
echo 'done', PHP_EOL;
$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);
$timer = $handler->addTimer('example_timer', 1, function (React\EventLoop\Timer\Timer $timer) {
echo 'example_timer', PHP_EOL;
});
$handler->cancelTimer('example_timer');
$loop->run();
echo 'done', PHP_EOL;
$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);
$timer = $handler->addPeriodicTimer('periodic_timer', 1, function (React\EventLoop\Timer\Timer $timer) {});
$loop->run();
$loop = \React\EventLoop\Factory::create();
$handler = new \Zwirek\React\Timer\Handler\TimerHandler($loop);
$timer = $handler->addLimitedPeriodicTimer('limited_periodic_timer', 1, function (React\EventLoop\Timer\Timer $timer) {}, 5);
$loop->run();
$handler->cancelAll();