Re: PHP True Async
| From: | Rob Landers | Date: | Tue, 18 Feb 2025 12:23:40 +0000 |
| Subject: | Re: PHP True Async | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126444@lists.php.net to get a copy of this message | ||
On Mon, Feb 17, 2025, at 20:31, Edmond Dantes wrote:
> > There should be no perceptible difference between a blocking sleep(10) and an async
> > sleep(10), so what backwards compatibility are you referring to?
>
> For example, the behavior of the code below will not change. The code will execute
> sequentially, and context switching will only occur when
>
resume/suspend is called.
>
> However, when the Scheduler is activated, this behavior
> changes. Now, calling sleep() inside a
> Fiber will lead to a context switch.
>
> If the activation of the Scheduler is implicit, previously
> written code may not work as the developer expects.
>
>
> <?php
>
> $fiber = new Fiber(function (): void {
> echo "Start fiber\n";
> sleep(1);
> Fiber::suspend("Paused");
> echo "Resume fiber\n";
> });
>
> $result = $fiber->start();
>
> echo "Fiber suspended with: $result\n";
>
> sleep(10);
>
> $fiber->resume();
>
> echo "Fiber finished\n";
I think what bilge was trying to point out is that there should be absolutely no change on existing
software with or without the scheduler running (for software not using fibers).
— Rob