Re: PHP True Async RFC - Stage 2

From: Date: Thu, 20 Mar 2025 14:56: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 18  Groups: php.internals 
Request: Send a blank email to internals+get-126862@lists.php.net to get a copy of this message
> > 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. > Is that really a problem? If a programmer wrote the code $x = 1 / 0, then the issue is definitely not with the division operation. > If you wanted to make it asynchronous, you'd have to do something like so: Because this is more of an anti-example :) You shouldn't write code like this. But if you really want to, at least do it like this: ```php $x = await spawn fn => [spawn file_get_contents($a), spawn file_get_contents($b), spawn file_get_contents($c)]; ``` But this is also an anti-example because what's the point of writing the same code three times when you can use a concurrent iterator? ```php $x = await Async\map([$a, $b, $c], "file_get_contents"); ``` (The functions will be included in another RFC)

« previous php.internals (#126862) next »