Swoole\Coroutine::getBackTrace

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


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Coroutine::getBackTrace(int $cid = 0, int $options = \DEBUG_BACKTRACE_PROVIDE_OBJECT, int $limit = 0): array|false

Parameters

cid

Coroutine ID. By default, use the ID of current coroutine.

options

DEBUG_BACKTRACE_PROVIDE_OBJECT

limit

the depth of the backtrace.

Return

backtrace

an array of backtrace.

Description

Get the backtrace of a coroutine by coroutine ID.

Example

<?php
function test1() {
    test2();
}

function test2() {
    while(true) {
        co::sleep(10);
        echo __FUNCTION__." \n";
    }
}

$cid = go(function () {
    test1();
});

go(function () use ($cid) {
    while(true) {
        echo "BackTrace[$cid]:\n-----------------------------------------------\n";
        var_dump(co::getBackTrace($cid))."\n";
        co::sleep(3);
    }
});
Last updated on August 31, 2022