Swoole\Event::cycle

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Event::cycle(callable $callback, bool $before = false)\:\ bool

Parameters

callback

callback function to executed every event loop cycle

before

before or after the event loop

Return

success

If success, it returns TRUE, meaning the event listener was successfully added

Otherwise it returns FALSE, meaning there was an issue registering the event

Description

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 round
  • true: Execute the function before the start of the event loop round

You can have two cycle functions operating when setting the before and after parameters

Example

<?php

Swoole\Timer::tick(2000, function ($id) {
    var_dump($id);
});

Swoole\Event::cycle(function () {

    echo "hello [1]\n";

    Swoole\Event::cycle(function () {

        echo "hello [2]\n";

        // Clear all cycle functions
        Swoole\Event::cycle(null);

    });

});
Last updated on August 31, 2022