- Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.23, 8.4.1 - 8.4.10
- Start Do something else Are there results? Do something else Are there results? Do something else Are there results? End
<?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";