Coroutine::getSuspendLocation

(PHP 8.6+, True Async 1.0)

public Coroutine::getSuspendLocation(): string

Returns the coroutine suspension location in the format "file:line". If the information is unavailable, returns "unknown".

Return Value

string – a string like "/app/script.php:42" or "unknown".

Examples

Example #1 Diagnosing a stuck coroutine

<?php

use function Async\spawn;
use function Async\suspend;
use function Async\get_coroutines;

spawn(function() {
    file_get_contents('https://slow-api.example.com'); // stuck here
});

suspend();

foreach (get_coroutines() as $coro) {
    if ($coro->isSuspended()) {
        echo "Coroutine #{$coro->getId()} waiting at: {$coro->getSuspendLocation()}\n";
    }
}

See Also