On Mon, 9 Aug 2021, 21:41 the mschop, <mschop...@gmail.com> wrote: > Hi all, > > This is my first time writing to the internals mailing list, so please > be patient with me. I would like to get feedback from you on the > following idea. The idea might seem crazy at the first glance, but the > longer I thought of it, the cooler I found the idea ;-). I would like > to share the idea with you and receive feedback. I would currently not > know how to implement it in the PHP lang. The only way I would be able > to do this right now with my skill set would be to write a transpiler > (which is not ideal), which compiles it to e.g. ReactPHP code. > > One of the main arguments against PHP is that PHP has a completely > empty state at the beginning of every request. This implies that on > every request all of the assets (e.g. configs) needs to be loaded. > Some applications load it from the database, which makes it even > worse. This causes slower response times than you can achieve with > other programming languages. > > One way to improve this is by using libraries like ReactPHP for adding > asynchronicity to PHP. This would enable one to load assets > concurrently, but migrating existing code bases to asynchronous code > would be a nightmare, so no one does it. Additionally, asynchronous > code is harder to read and write. > > My suggestion is to add the iasync keyword to PHP. By using the iasync > keyword, functions or code blocks could be marked as "eventually > async". > > 'eventually async', because it should be possible to disable the > functionality with an ini setting (especially for debugging purposes). > > The keyword could be used on a method level: > > public static iasync function doSomething() { ... } > > Alternatively it could be used for wrapping a code block: > > iasync { > // contained code > } > > All blocking IO operations in iasync context would then not return the > actual value, but instead a promise. > Those promises are automatically awaited in the following cases: > > - The variables value is accessed > - The iasync context is left > - A non-iasync code block is invoked > > Example (variable access): > > iasync { > $fileContent = file_get_contents('path'); // returns a promise > $arr = [$fileContent]; // not awaited, because the actual value is > not relevant right now > echo($fileContent); // now the code would block, because the value is > needed > } > > Example (context left): > > iasync { > $fileContent = file_get_contents('path'); // returns a promise > } // leaving context would block, until value available > echo $fileContent; > > ####### > Promises > ####### > > The promises are not like promises of other languages. They are > implicit and programmers cannot do anything with it. > > ################################ > What is the advantage of this approach? > ################################ > > Many applications could profit by iasync because it's so simple to > use. Application performance could be greatly improved. > > Thank you! > > Best regards > mschop > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.ph > <https://www.php.net/unsub.php>
Hi, Looks kinda similar to what Amphp does with yield and generators? Did you check that? Olle