1. Go to this page and download the library: Download axcherednikov/eventloop 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/ */
axcherednikov / eventloop example snippets
use EventLoop\EventLoop;
// Defer a callback to the next loop tick
EventLoop::defer(function (string $callbackId) {
echo "Deferred callback executed\n";
});
// Delay execution by 1.5 seconds
EventLoop::delay(1.5, function (string $callbackId) {
echo "This runs after 1.5 seconds\n";
});
// Repeat every 500ms
$id = EventLoop::repeat(0.5, function (string $callbackId) {
echo "Tick\n";
});
// Cancel the repeater after 3 seconds
EventLoop::delay(3, function () use ($id) {
EventLoop::cancel($id);
});
EventLoop::run();