Coroutine::getBackTrace

获取协程函数调用栈。

function Coroutine::getBackTrace(int $cid=0, int $options=DEBUG_BACKTRACE_PROVIDE_OBJECT, int $limit=0) : array;

需要4.1.0或更高版本

参数

返回值

使用实例

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);
    }
});