Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115689 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32590 invoked from network); 11 Aug 2021 08:09:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Aug 2021 08:09:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3E0E4180088 for ; Wed, 11 Aug 2021 01:40:09 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 ; Wed, 11 Aug 2021 01:40:08 -0700 (PDT) Received: by mail-pl1-f178.google.com with SMTP id d17so1699759plr.12 for ; Wed, 11 Aug 2021 01:40:08 -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:content-transfer-encoding; bh=jLsq96NBrtgCBvaLy5S04o3ho5kkKlJFIfKV6B6BdUM=; b=ly7tyot1f2SHUG9QAAXaCMgJ7yl/w20cqZXEfqjuHSrzjicnHp7epNpYQtX4ZobwsF ptKvsQUcnUoQZv4XlJaGbCqkCLbCO0H5Zq1udQs7sO9whQreSH7kGO30JTRHRxvB7aDf GXl2FRMzErRk8XFC4EOQWZN+uj+jRaQjuukrD0wO9oBmc8t5q5dFAxrQE7Ia9afKVfUP ecQazmtEwN/2wzQpHva8WVdlNjBJWVG30ygKftSbE/jI8axGqFehzXFwEbdPs3CVblYa kTW9K4qnJVEfftsguErHyLb0mioD7HqniDznsQFyCblXpFMc1Us2ufpEyhSnN6gkxgcT 1crQ== 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:content-transfer-encoding; bh=jLsq96NBrtgCBvaLy5S04o3ho5kkKlJFIfKV6B6BdUM=; b=ZwxWkFkeJB4nbsxbjr6/5or9ISa92MPJvXxJjTuf6+vEChy4qNgbTg6RsC8fa6l7DY koml4o4Lh3iapZvLppNvrcqA90nkeQjCgGbS6TkkRTvWsfx+8b7vHvwfcr3RMb8zdKsH DISqgpf8qdVeWcAd105A1e9709hf7JzcsvR5OUia6XMkzsKqhk7ZNwiqeLss5Ms1/xOl wZUxlWHStDUKzV9wSCNNemtJXXuI4X+EQUjb/ABJDq5iX0W4hYwZrqy8eU2qg2VfmNyP sleLYW49kZkO0XrfVRv1r5jQ0OdUH/Sw8SHlo0efkyufBOLFPoRoxJGkXKnmSQ3yFzYj 3wDw== X-Gm-Message-State: AOAM5330qUzOhsGEW1WINWLcSwq6EwuAPkcDRFt2ILYXkq81Q/yqa0ll SeOVYDLOMxyn3EQPkAZVjtscG+rzPtU0SnAwdag= X-Google-Smtp-Source: ABdhPJwLAgLZgD6BfFMYRM4OEg8rEM3cPsviTlAscYRvpBxNY0iIS8X9FR2DdaJI53jsLdX9t7svkFgylziOeXacN5s= X-Received: by 2002:a63:5317:: with SMTP id h23mr485569pgb.446.1628671206092; Wed, 11 Aug 2021 01:40:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 11 Aug 2021 10:39:57 +0200 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC Implicit Async (iasync) From: mschopdev@gmail.com (the mschop) On Mon, Aug 9, 2021 at 10:50 PM Olle H=C3=A4rstedt = wrote: > > > > 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 =3D file_get_contents('path'); // returns a promise >> $arr =3D [$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 =3D 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 Hi Olle, I already used amphp. Using amphp still means that the application needs to be rewritten. Only amphp or reactphp libraries would be non-blocking. So one would need to exchange most libraries one currently uses. mschop