3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(ini_get('memory_limit')); echo "\n"; $shallowFiberFactoryFiber = new Fiber(function(): void { $fiberNumber = 0; while (true) { $res = new Fiber(function (\Closure $fx) use (&$fiberNumber): void { $res = $fx($fiberNumber++); Fiber::suspend($res); }); Fiber::suspend($res); } }); $shallowFiberFactoryFx = function () use ($shallowFiberFactoryFiber): \Fiber { return !$shallowFiberFactoryFiber->isStarted() ? $shallowFiberFactoryFiber->start() : $shallowFiberFactoryFiber->resume(); }; $i = 0; $fx = function (int $fiberNumber) use ($shallowFiberFactoryFx): void { $res = array_map(function ($str) use ($shallowFiberFactoryFx, $fiberNumber) { global $i, $fx; $i++; // log/debug execution if (($i % 1_000) === 0) { var_dump($i . ' at fiber: ' . $fiberNumber); } // terminating cond if ($i > 50_000) { return 'finished at fiber: ' . $fiberNumber; } // recurse - every 2k reentry unroll the machine stack using Fiber return ($i % 2_000) === 0 ? $shallowFiberFactoryFx()->start($fx)[0] : $fx($fiberNumber); }, ['x']); Fiber::suspend($res); }; $res = $shallowFiberFactoryFx()->start($fx); echo "\n"; print_r($res);

preferences:
24.13 ms | 407 KiB | 5 Q