Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115677 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 61074 invoked from network); 9 Aug 2021 20:20:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Aug 2021 20:20:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C2C44180542 for ; Mon, 9 Aug 2021 13:50:58 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 9 Aug 2021 13:50:58 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id x9so23587773ljj.2 for ; Mon, 09 Aug 2021 13:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B3X7LOidRqJ5BW/pUDO1NJ4mDoR7lx0HuD/QosvKo7M=; b=quhWaI0M6FxOkaOj7JFxSL7mpUOHtLWYEk8urMZ2k9+Q8f8AyTjyn/TUUVh9Smca/W y9iExw11K4N5LpyLGSl0KX8dv7Sq+O52FV112OYd3fqtPMwFwLDaly7xxEnBjhVJNrfm lb/xcO9L15b24zKJ2d4Ly5wu1fT8CCoG0Sz866C8chBdzPsuC7MUuj6NFAJj3UbgZZwU K27tuY2GvaAVwz6ZHR+VDZEh/e4MJ0RZYoWBAwvNScAZvlW51nr1OFLuuoZsSkbfA7jO lGXJc+xmFg3mxWPyveCbRXXrnfI8tMS75TL3+fc0v8J5NSSwligra1yNSNePjEiDTvOY LQrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B3X7LOidRqJ5BW/pUDO1NJ4mDoR7lx0HuD/QosvKo7M=; b=p16wV7TpFKynL0516zkXIOlz6MKMmDs1PGmeJW+RzMUHEJLPbWIz+vgVxbWt6RtzV5 0wSOcD2UR/dWaRwCY4LEXZ4Fzp25JeVynek/M11iTC4coToHH4k8rpuLofQir0t3YXNa 8hPVgTKn9cn1yaVX89HMcrxENLqQwK9rmOV0myjvADnGZpMCFxpaXnq6PclgXK+6wgG9 W8BrNSflV/uVVDG9w2wvC//PMPfqPB3DNoZyZ13aG0MVO9EK/DrhmnaJQYV8NkbgFRJp sAkrmMGS6FRR84SlVLcdkqjlTTqEq3CSDyoeYrxjlDMPvB74E1pCZJ12s4hyYJlLjZ43 14sA== X-Gm-Message-State: AOAM5304PeS2c8SNXy80h9Zahr6pRI3nciNTdkWcMlB3bWauRo9ITDsm u5kqH9r1rZunpWVFz0YtHOnZxVWLldw6zoDBo9M= X-Google-Smtp-Source: ABdhPJx1JMnFQiO0tDwZ3NN+l3cEWusi71GTZ8WdYaik9DYVlmhl30r92wcMySq/7v/5Dr2j0J1mDyHh5shLBa2a1Zg= X-Received: by 2002:a2e:95c1:: with SMTP id y1mr16946584ljh.71.1628542256708; Mon, 09 Aug 2021 13:50:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 9 Aug 2021 22:50:44 +0200 Message-ID: To: the mschop Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000b6817705c9268ac5" Subject: Re: [PHP-DEV] RFC Implicit Async (iasync) From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) --000000000000b6817705c9268ac5 Content-Type: text/plain; charset="UTF-8" On Mon, 9 Aug 2021, 21:41 the mschop, 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 > Hi, Looks kinda similar to what Amphp does with yield and generators? Did you check that? Olle --000000000000b6817705c9268ac5--