OpenSwoole\Coroutine::defer

25.x is outdated, please check the latest version 26.x


Latest version: pecl install openswoole-26.2.0

Declaration

<?php OpenSwoole\Coroutine::defer(callable $callback): void

Parameters

callback

Closure function to be deferred.

Return

Description

Execute the deferred function to be executed at the time when the current coroutine is exiting.

Example

<?php

function task() {
    echo '3' . PHP_EOL;
}

co::run(function () {
    go(function () {
        echo '1' . PHP_EOL;
        OpenSwoole\Coroutine::defer('task');
        echo '2' . PHP_EOL;
    });
});
Last updated on February 28, 2026