Swoole Server defer

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