Swoole Server defer

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


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Server->defer(callable $callback): void

Parameters

callback

Execute the callback at the end of the current event loop cycle

Return

none

Description

Delay execution of the callback function at the end of current EventLoop cycle. Alias of function swoole_event_defer() or defer().

The callback is executed once the current event loop cycle completes, the purpose of that is to delay execution that does not need to happen immediately and let it execute once the event loop has completed its cycle.

See Swoole Event Defer.

Example

<?php

// Inside the Swoole Server...
function query($server, $db)
{
    $server->defer(function() use ($db)
    {
        $db->close();
    });
}

There are four types of callback functions

Last updated on August 31, 2022