Re: [VOTE] True Async RFC 1.6

From: Date: Sat, 22 Nov 2025 11:46:18 +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-129388@lists.php.net to get a copy of this message
> Thomas Bley <mails@thomasbley.de> hat am 22.11.2025 12:42 CET geschrieben: > > > > Edmond Dantes <edmond.ht@gmail.com> hat am 22.11.2025 11:37 CET geschrieben: > > > > > > Hello > > > > > I expect that's already a good improvement for many use cases to read multiple > > > files in parallel, run multiple queries in parallel, etc. > > > > I see. You want to get several promises to wait for? > > Then there is a good way to do it without additional functions: > > > > ```php > > $promise1 = spawn(file_get_content(...), "file1.txt"); > > $promise2 = spawn(file_get_content(...), "file2.txt"); > > $promise3 = spawn(file_get_content(...), "file3.txt"); > > ``` > > > > This is equivalent because a coroutine is a Future. In the same way, > > you can turn any other function into a Promise without creating a > > separate API. > > > > There is a nuance regarding resources. And in certain scenarios, > > creating an array of Promises in another way can save memory. For > > example, a scenario where you need to handle a large array of sockets. > > Such cases require a special API. > > > > --- > > Ed > > Hello, > > function return types should not depend on the outside context (spawn, hook, ini, etc.) because > when the code gets more complex, it's very hard to find the outside context. > > So file_get_contents() should always return string|false, file_get_contents_async() should > always return a promise object. > > From the example I would expect it like this: > > $promise1 = file_get_content_async("file1.txt"); > $promise2 = file_get_content_async("file2.txt"); > $promise3 = file_get_content_async("file3.txt"); > > // do sth else > > $content1 = $promise->await(); > $content2 = $promise->await(); > $content3 = $promise->await(); > > PHP got very successful by making things easier than in C, this should be the path to continue. > > Best Regards > Thomas I'm sorry, the correct example should be: $promise1 = file_get_content_async("file1.txt"); $promise2 = file_get_content_async("file2.txt"); $promise3 = file_get_content_async("file3.txt"); // do sth else $content1 = $promise1->await(); $content2 = $promise2->await(); $content3 = $promise3->await(); Best Regards Thomas

« previous php.internals (#129388) next »