Coroutine::getSpawnLocation
(PHP 8.6+, True Async 1.0)
public Coroutine::getSpawnLocation(): string
Returns the coroutine creation 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 Debug output
<?php
use function Async\spawn;
$coroutine = spawn(fn() => "test");
echo "Created at: " . $coroutine->getSpawnLocation() . "\n";
// Output: "Created at: /app/script.php:5"
Example #2 Logging all coroutines
<?php
use function Async\spawn;
use function Async\get_coroutines;
spawn(fn() => Async\delay(1000));
spawn(fn() => Async\delay(2000));
foreach (get_coroutines() as $coro) {
echo "Coroutine #{$coro->getId()} created at {$coro->getSpawnLocation()}\n";
}
See Also
- Coroutine::getSpawnFileAndLine – File and line as an array
- Coroutine::getSuspendLocation – Suspension location
- get_coroutines() – All active coroutines