3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fiber = new Fiber(function() { $count = 3; echo "Start\n"; while(true) { Fiber::suspend(); // suspend the fiber echo "Are there results?\n"; $count--; if ($count === 0) { return; // We received the results, we stop } } }); $fiber->start(); // Initiates processing do { echo "Do something else\n"; $fiber->resume(); // Restart the fiber } while (!$fiber->isTerminated()); // The fiber has terminated echo "End\n";
Output for 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Start Do something else Are there results? Do something else Are there results? Do something else Are there results? End
Output for 8.0.0
Fatal error: Uncaught Error: Class "Fiber" not found in /in/YrDZ0:2 Stack trace: #0 {main} thrown in /in/YrDZ0 on line 2
Process exited with code 255.
Output for 7.0.33, 7.3.33
Fatal error: Uncaught Error: Class 'Fiber' not found in /in/YrDZ0:2 Stack trace: #0 {main} thrown in /in/YrDZ0 on line 2
Process exited with code 255.

preferences:
79.53 ms | 408 KiB | 5 Q