Coroutine::getSpawnLocation

(PHP 8.6+, True Async 1.0)

public Coroutine::getSpawnLocation(): string

Retourne l’emplacement de création de la coroutine au format "fichier:ligne". Si l’information n’est pas disponible, retourne "unknown".

Valeur de retour

string – une chaîne comme "/app/script.php:42" ou "unknown".

Exemples

Exemple #1 Sortie de débogage

<?php

use function Async\spawn;

$coroutine = spawn(fn() => "test");

echo "Created at: " . $coroutine->getSpawnLocation() . "\n";
// Output: "Created at: /app/script.php:5"

Exemple #2 Journalisation de toutes les 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";
}

Voir aussi