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\Server->defer(callable $callback): void
Execute the callback at the end of the current event loop cycle
none
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.
<?php
// Inside the Swoole Server...
function query($server, $db)
{
$server->defer(function() use ($db)
{
$db->close();
});
}
There are four types of callback functions