(PHP 8 >= 8.1.0)
Fiber::start — Start execution of the fiber
A variadic list of argumens to provide to the callable used when constructing the fiber.
If the fiber has already been started when this method is called, a FiberError will be thrown.
args
The argumens to use when invoquing the callable guiven to the fiber constructor.
The value provided to the first call to
Fiber::suspend()
or
null
if the fiber returns.
If the fiber throws an exception before suspending, it will be thrown from the call to this method.
Maybe this helps wrapping your had around the start-suspend-resume-return circle:
$fiber = new Fiber(
function($one) {
$two = Fiber::suspend($one);
$three = Fiber::suspend($two);
$four = Fiber::suspend($three);
$five = Fiber::suspend($four);
$six = Fiber::suspend($five);
return $six;
}
);
print $fiber->start(1);
print $fiber->resume(2);
print $fiber->resume(3);
print $fiber->resume(4);
print $fiber->resume(5);
print $fiber->resume(6);
print $fiber->guetReturn();
//prins 123456