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);
Output for 8.4.1 - 8.4.12
string(3) "64M" string(16) "1000 at fiber: 0" string(16) "2000 at fiber: 0" string(16) "3000 at fiber: 1" string(16) "4000 at fiber: 1" string(16) "5000 at fiber: 2" string(16) "6000 at fiber: 2" string(16) "7000 at fiber: 3" string(16) "8000 at fiber: 3" string(16) "9000 at fiber: 4" string(17) "10000 at fiber: 4" string(17) "11000 at fiber: 5" string(17) "12000 at fiber: 5" string(17) "13000 at fiber: 6" string(17) "14000 at fiber: 6" string(17) "15000 at fiber: 7" string(17) "16000 at fiber: 7" string(17) "17000 at fiber: 8" string(17) "18000 at fiber: 8" string(17) "19000 at fiber: 9" string(17) "20000 at fiber: 9" string(18) "21000 at fiber: 10" string(18) "22000 at fiber: 10" string(18) "23000 at fiber: 11" string(18) "24000 at fiber: 11" string(18) "25000 at fiber: 12" string(18) "26000 at fiber: 12" string(18) "27000 at fiber: 13" string(18) "28000 at fiber: 13" Fatal error: Out of memory (allocated 50331648 bytes) (tried to allocate 20480 bytes) in /in/0Jjrr on line 43 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.2.18 - 8.2.29, 8.3.5 - 8.3.25
string(3) "64M" string(16) "1000 at fiber: 0" string(16) "2000 at fiber: 0" string(16) "3000 at fiber: 1" string(16) "4000 at fiber: 1" string(16) "5000 at fiber: 2" string(16) "6000 at fiber: 2" string(16) "7000 at fiber: 3" string(16) "8000 at fiber: 3" string(16) "9000 at fiber: 4" string(17) "10000 at fiber: 4" string(17) "11000 at fiber: 5" string(17) "12000 at fiber: 5" string(17) "13000 at fiber: 6" string(17) "14000 at fiber: 6" string(17) "15000 at fiber: 7" string(17) "16000 at fiber: 7" string(17) "17000 at fiber: 8" string(17) "18000 at fiber: 8" string(17) "19000 at fiber: 9" string(17) "20000 at fiber: 9" string(18) "21000 at fiber: 10" string(18) "22000 at fiber: 10" string(18) "23000 at fiber: 11" string(18) "24000 at fiber: 11" string(18) "25000 at fiber: 12" string(18) "26000 at fiber: 12" string(18) "27000 at fiber: 13" string(18) "28000 at fiber: 13" string(18) "29000 at fiber: 14" string(18) "30000 at fiber: 14" Fatal error: Out of memory (allocated 52428800 bytes) (tried to allocate 36864 bytes) in /in/0Jjrr on line 43 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
string(3) "64M" string(16) "1000 at fiber: 0" string(16) "2000 at fiber: 0" string(16) "3000 at fiber: 1" string(16) "4000 at fiber: 1" string(16) "5000 at fiber: 2" string(16) "6000 at fiber: 2" string(16) "7000 at fiber: 3" string(16) "8000 at fiber: 3" string(16) "9000 at fiber: 4" string(17) "10000 at fiber: 4" Fatal error: Out of memory (allocated 18874368 bytes) (tried to allocate 20480 bytes) in /in/0Jjrr on line 43 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.28 - 8.1.33
string(3) "64M" string(16) "1000 at fiber: 0" string(16) "2000 at fiber: 0" string(16) "3000 at fiber: 1" string(16) "4000 at fiber: 1" string(16) "5000 at fiber: 2" string(16) "6000 at fiber: 2" string(16) "7000 at fiber: 3" string(16) "8000 at fiber: 3" string(16) "9000 at fiber: 4" string(17) "10000 at fiber: 4" string(17) "11000 at fiber: 5" string(17) "12000 at fiber: 5" string(17) "13000 at fiber: 6" string(17) "14000 at fiber: 6" string(17) "15000 at fiber: 7" string(17) "16000 at fiber: 7" string(17) "17000 at fiber: 8" string(17) "18000 at fiber: 8" string(17) "19000 at fiber: 9" string(17) "20000 at fiber: 9" string(18) "21000 at fiber: 10" string(18) "22000 at fiber: 10" string(18) "23000 at fiber: 11" string(18) "24000 at fiber: 11" string(18) "25000 at fiber: 12" string(18) "26000 at fiber: 12" string(18) "27000 at fiber: 13" string(18) "28000 at fiber: 13" Fatal error: Out of memory (allocated 54525952) (tried to allocate 20480 bytes) in /in/0Jjrr on line 27 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.24 - 8.1.27
string(3) "64M" string(16) "1000 at fiber: 0" string(16) "2000 at fiber: 0" string(16) "3000 at fiber: 1" string(16) "4000 at fiber: 1" string(16) "5000 at fiber: 2" string(16) "6000 at fiber: 2" string(16) "7000 at fiber: 3" string(16) "8000 at fiber: 3" Fatal error: Out of memory (allocated 16777216) (tried to allocate 20480 bytes) in /in/0Jjrr on line 27 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.2 - 8.1.23
string(3) "64M" string(16) "1000 at fiber: 0" string(16) "2000 at fiber: 0" string(16) "3000 at fiber: 1" string(16) "4000 at fiber: 1" string(16) "5000 at fiber: 2" string(16) "6000 at fiber: 2" string(16) "7000 at fiber: 3" string(16) "8000 at fiber: 3" Fatal error: Out of memory (allocated 16777216) (tried to allocate 20480 bytes) in /in/0Jjrr on line 26 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.0 - 8.1.1
string(3) "64M" string(16) "1000 at fiber: 0" string(16) "2000 at fiber: 0" string(16) "3000 at fiber: 1" string(16) "4000 at fiber: 1" string(16) "5000 at fiber: 2" string(16) "6000 at fiber: 2" string(16) "7000 at fiber: 3" string(16) "8000 at fiber: 3" string(16) "9000 at fiber: 4" string(17) "10000 at fiber: 4" string(17) "11000 at fiber: 5" string(17) "12000 at fiber: 5" string(17) "13000 at fiber: 6" string(17) "14000 at fiber: 6" string(17) "15000 at fiber: 7" string(17) "16000 at fiber: 7" string(17) "17000 at fiber: 8" string(17) "18000 at fiber: 8" string(17) "19000 at fiber: 9" string(17) "20000 at fiber: 9" string(18) "21000 at fiber: 10" string(18) "22000 at fiber: 10" string(18) "23000 at fiber: 11" string(18) "24000 at fiber: 11" string(18) "25000 at fiber: 12" string(18) "26000 at fiber: 12" Fatal error: Out of memory (allocated 50331648) (tried to allocate 16384 bytes) in /in/0Jjrr on line 45 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.0.1 - 8.0.30
string(3) "64M" Fatal error: Uncaught Error: Class "Fiber" not found in /in/0Jjrr:6 Stack trace: #0 {main} thrown in /in/0Jjrr on line 6
Process exited with code 255.
Output for 7.4.0 - 7.4.33
string(3) "64M" Fatal error: Uncaught Error: Class 'Fiber' not found in /in/0Jjrr:6 Stack trace: #0 {main} thrown in /in/0Jjrr on line 6
Process exited with code 255.

preferences:
90.45 ms | 422 KiB | 5 Q