Re: [VOTE] True Async RFC 1.6
| From: | Thomas Bley | Date: | Sat, 22 Nov 2025 14:40:26 +0000 |
| Subject: | Re: [VOTE] True Async RFC 1.6 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129396@lists.php.net to get a copy of this message | ||
> Edmond Dantes <edmond.ht@gmail.com> hat am 22.11.2025 14:55 CET geschrieben:
>
>
> > So I guess you want to use spawn() in a similar way as call_user_func() works.
> yes
>
> > This changes the behavior of file_get_contents() from the outside
> No.
>
> ```php
> function file_get_contents(string $filename): string
> {
> $fh = fopen();
>
> // It creates an EPOLL event so it can wake us when the data
> becomes available.
> $event = ReactorAPI.create_event_from($fh);
> $waker = Scheduler.getCurrentWaker();
> // Event Driven logic inside.
> $waker.add_event($event, function() use($waker) {
> // Wakeup this coroutine
> $waker.wake();
> });
>
> // suspend current coroutine
> // zz..... z.....
> Scheduler.suspend();
>
> // Continue here after the IO event
>
> // Now we have date, return
> return fread($fh, ....);
> }
> ```
>
> This is pseudocode. You can assume it always works.
> If you call
file_get_contents directly, it behaves the same
> way.
> So it does not matter where file_get_contents is called.
> Since all PHP code together with TrueAsync runs inside coroutines,
> file_get_contents will suspend the coroutine in which it was
> invoked.
>
> When you call spawn, you simply run the function in another
> coroutine, not in your own. But spawn has no effect on
> file_get_contents.
>
> We’re not at risk of DataRace yet :) We don’t have multithreading.
> And most likely it won’t appear anytime soon.
> // Continue here after the IO event
From my understanding, the code does not continue if there is no io event? Will it use
default_socket_timeout from php.ini and/or use the timeout specified in the stream context?
Can I mix sync IO and async IO in one function? e.g. if the server uses a mixed storage of SSDs and
HDDs and I only want async io for the SSDs?
Best Regards
Thomas