Coroutine::getSpawnLocation

(PHP 8.6+, True Async 1.0)

public Coroutine::getSpawnLocation(): string

Gibt den Erstellungsort der Coroutine im Format "Datei:Zeile" zurueck. Wenn die Information nicht verfuegbar ist, wird "unknown" zurueckgegeben.

Rueckgabewert

string – eine Zeichenkette wie "/app/script.php:42" oder "unknown".

Beispiele

Beispiel #1 Debug-Ausgabe

<?php

use function Async\spawn;

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

echo "Erstellt in: " . $coroutine->getSpawnLocation() . "\n";
// Ausgabe: "Erstellt in: /app/script.php:5"

Beispiel #2 Alle Coroutinen protokollieren

<?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()} erstellt in {$coro->getSpawnLocation()}\n";
}

Siehe auch