OpenSwoole\Coroutine::getBackTrace

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\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 September 1, 2022