Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Event::cycle(callable $callback, bool $before = false)\:\ bool
callback function to executed every event loop cycle
before or after the event loop
If success, it returns TRUE, meaning the event listener was successfully added
Otherwise it returns FALSE, meaning there was an issue registering the event
Register a callback function which is executed every loop, you can set if this function or callable executes before or after the event loop round:
bool $before:
false
: Execute the function after the event loop roundtrue
: Execute the function before the start of the event loop roundYou can have two cycle functions operating when setting the before and after parameters
<?php
OpenSwoole\Timer::tick(2000, function ($id) {
var_dump($id);
});
OpenSwoole\Event::cycle(function () {
echo "hello [1]\n";
OpenSwoole\Event::cycle(function () {
echo "hello [2]\n";
// Clear all cycle functions
OpenSwoole\Event::cycle(null);
});
});