Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115675 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53546 invoked from network); 9 Aug 2021 19:10:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Aug 2021 19:10:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AD6E9180212 for ; Mon, 9 Aug 2021 12:40:51 -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=-0.2 required=5.0 tests=BAYES_20,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-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 12:40:51 -0700 (PDT) Received: by mail-pj1-f54.google.com with SMTP id t7-20020a17090a5d87b029017807007f23so554038pji.5 for ; Mon, 09 Aug 2021 12:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=3B9K6dbVADI/hBMYlDL8WnGd+tsSq97NETVzLUQs8r8=; b=svfWpX+PK7NX1uQHqjnvN0mCwPKaVnZGLMvcpmjsSZUjc82RYfmtx+tJSog3M2SExt x71hLi2IQ6dDrzFCF0gjItzMZhRGNa81HdpfrOzd7TmKCN/C7ljxKu6aKmuQfNoL3n5g KXUvPgTNj699hbjN7VugWqHzfkbiUgFRidXo3JSraMquezJ14sETh1tUYDBJ17rHivMY 3z9FLmgPvXAXLWMHkMJ9nnVArGNIIl+apbgk37vOtqU4/ahYMIEvMzWvdFgK0Ty3ohlf XmBxs+oo65FnaHXlnv8WZEPOr2GYIvwUT89GOaw2LVBbOCdOsh8umEysNH42WxKrv+9g qDwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=3B9K6dbVADI/hBMYlDL8WnGd+tsSq97NETVzLUQs8r8=; b=Qnh/yPnHJ0gwFRSVf2dNPyza4XDGGqsxY23HY1bHwD4DXy4wPLzLX+c1KLcEP/TbzZ jCLlgMiF9KA9H6zMqGLRuw5Ee7gKSDOIYQazk3OCxZFVPpv7cOaKdIyVf9WER8foOxR0 RzBELi2Nxz8+D8sYYxxJqY0T2hkfbjVy4+by6ZDi+CNy83yqzGugVw7JaEQYn4MnZfrq 3WAhppAUDLWw9GRwRvj/yvlNhz9tZsJAR3snhvYAc07wJxsndJ4EjacMQW1A1uhnBzTn uMjc5qyYHPHxfryTUvYZsmIVoPV8fJhcLIMLAUrImBIA0hMf+u3Mszo3//v+mD0E5VyT s5Sg== X-Gm-Message-State: AOAM533YYYyOrBdxWw3Wu48ndug/rDtQEuU37rDXRELARbypJKnrQTmA gedAtNxT+A1ZMQz98GQzDcDe6De6JfURhuYTkgImxwzHAo0= X-Google-Smtp-Source: ABdhPJxWqQWfga3LLOJOSM3y0aiIgcnsnkVjOq+l5b3brKi/eMxhnUmPFQbD41Xx17jqjnpUk1fZLpGuKoH5APr7Zls= X-Received: by 2002:a17:90a:c57:: with SMTP id u23mr740630pje.186.1628538048851; Mon, 09 Aug 2021 12:40:48 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 9 Aug 2021 21:40:38 +0200 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: RFC Implicit Async (iasync) From: mschopdev@gmail.com (the mschop) 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