Re: PHP True Async RFC - Stage 2

From: Date: Thu, 20 Mar 2025 14:14:55 +0000
Subject: Re: PHP True Async RFC - Stage 2
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


On Thu, Mar 20, 2025, at 12:01, Edmond Dantes wrote:
> ```php
> spawn fn() => [file_get_content(), file_get_content(), file_get_content()]
> ```

This example highlights one of the concerns I have with fibers and this approach in general. That
example will still execute synchronously, taking file_get_contents() * 3, even though it is in a
coroutine function.

If you wanted to make it asynchronous, you'd have to do something like so:

$x = [spawn fn() => file_get_contents($a), spawn fn() => file_get_contents($b), spawn fn()
=> file_get_contents($c)];

foreach($x as $i => $spawn) $x[$i] = await $spawn;

That is quite a bit more work than I'd like just to get async file reading done.

— Rob


Thread (59 messages)

« previous php.internals (#126860) next »