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.90.0060.00217.00
8.5.80.0050.00418.66
8.5.70.0220.01116.64
8.4.240.0140.00919.73
8.4.230.0070.00419.60
8.4.220.0050.00519.49
8.4.90.0050.00518.02
8.3.330.0100.01218.60
8.3.320.0030.00618.60
8.3.180.0050.00516.68
8.3.50.0070.00316.78
8.2.320.0080.00318.21

preferences:
49.22 ms | 528 KiB | 5 Q