3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Illustrates: $fiber->throw($exception) resumes the fiber and raises the // exception exactly where Fiber::suspend() paused it, not in the caller's scope. $fiber = new Fiber(function (): void { echo "fiber: starting\n"; try { $value = Fiber::suspend('paused, waiting for input'); echo "fiber: resumed normally with '{$value}'\n"; } catch (RuntimeException $e) { // This ordinary try/catch, wrapped around suspend(), catches the // exception injected by Fiber::throw() -- no special API needed. echo "fiber: caught injected exception: '{$e->getMessage()}'\n"; } echo "fiber: finishing\n"; }); echo "main: getCurrent() outside any fiber is: "; var_dump(Fiber::getCurrent()); $suspendedValue = $fiber->start(); echo "main: fiber suspended with '{$suspendedValue}'\n"; // This does NOT throw here, in main's scope. It resumes the fiber and the // exception surfaces at the suspend() call above, inside the fiber's body. $fiber->throw(new RuntimeException('something went wrong')); echo "main: fiber finished? " . ($fiber->isTerminated() ? 'yes' : 'no') . "\n"; // Starting an already-started (and now terminated) fiber is not a silent // no-op: it throws a FiberError. try { $fiber->start(); } catch (FiberError $e) { echo "main: caught FiberError: '{$e->getMessage()}'\n"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.70.0220.01116.64

preferences:
51.4 ms | 481 KiB | 5 Q