Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129374 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id B8DC41A00BC for ; Fri, 21 Nov 2025 15:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763739514; bh=WuVN+nh3Mc8OD8o2BR5UCZ3/gDdlshzNlTcq44BlhLU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cQGLwGZU58Yz1L3/wzLmOUHYD9UA8F4Kwl/G8mNUCghzOxqEIc1FHNKpQTkxnlcEn KMvrJ1nrPL/54HkaW9IGeRmAEpjHDFyqn2xztU26r0JVkTXCfaBziJxvloweQk1ytM hQU71sLeSpA03Wp4d4A7VkXh7aKQG3gfvwu3acPx14D02U+OWxnoXqY0t76Mi6FwqW 3lI+zr/ZRhGZ8o/eyGDJjWCraffTIk591XJopyzSEXhsr+zMgCpB7/scPucYiEX+WP t38oS+jW6RLQkS0ggfBhXuI33kKSLromtKlQhCIIFgtsxHQNxtcCbkxk6PQvHY3Cb4 kYMjD7wurW6yA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 567E11805B3 for ; Fri, 21 Nov 2025 15:38:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f51.google.com (mail-vs1-f51.google.com [209.85.217.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 21 Nov 2025 15:38:33 +0000 (UTC) Received: by mail-vs1-f51.google.com with SMTP id ada2fe7eead31-5dfa9e34adbso1715468137.0 for ; Fri, 21 Nov 2025 07:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763739507; x=1764344307; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WuVN+nh3Mc8OD8o2BR5UCZ3/gDdlshzNlTcq44BlhLU=; b=IsHQZYL30BWoVIqGBg6bldhzm/djBFue/pX2iIEo6xmOjSuHpJXH/prKLpcv4CQzgs ulzG3+wSTRQHZBSVCxRQGSoOigzvJWexxxLbHM7C/SgPnJtv5cdBP1cLBELUJTZpLdha wp4k3EYJfnXrAl5/RRPzFfKVuaWfucuZH+u8buqVaK/DEksOfkIvDU7rp66egZJ7raws VcEtlEA1+5a8kk1sfhofjKPmkjj4O/rxTGsWKCh7eXDmzDGqXtlJ0OMl+E2BN15sVkeU 6rFpif+AFx/Jtv7FX6Hf0YcnYE+ylh+B46cxQLW1n6XxabFfSRgiiXTXWlLwnm+fiz33 0OIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763739507; x=1764344307; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WuVN+nh3Mc8OD8o2BR5UCZ3/gDdlshzNlTcq44BlhLU=; b=Ub7fR+YYLWBpIVO9yFS5khI2drjeot5FF4ENgatyeyMbtUkO9V6OnM9MtjvkUEZmQs eeIivRXXYwwVwwk8Hx+u2QwZc65amb6XVJF1zrl9seHrd6WMpUX/dFfBBiRbpgTVGBDf 7iEcytAbdXS0DOObvMyIWyNSdKillTihwIGDqURsyDqFMpjModozbLxYQDuNdT8NdzOg xZYf36k2i65xcE0LWzWMdUtu2KNQQYuplknM3JXSMtblmpGCmBcG5rMtZyzpKjYPttQP 7dzBARe2fRUqd0rZaYrfw2wtU6EKPALNt+jGCM76oNYLbHYp3wcbfpC0BP30JVg3oOLk rEDg== X-Gm-Message-State: AOJu0Yxb5lwV+cay/Xw58OA8uH0Lqj+l8KAKeg1OHzBEzN3Vv4czvN2V 9RIotld+jy2IkRkMJD9BsWq7nf6RpvfGDnRwqoMk5QwKvZU/EkmsvfUZuDetDJtS0rKCfg3nBZ8 nRlFLVh9eblA5MvNtJCeO4Vt4Wb2M8hIwnZ4Tc78= X-Gm-Gg: ASbGnctlNC+3zI38+uveXnTlx/TKCd1TE/aJRUxV3TwZ3q8z416EFSyjRh0DncLi2M9 AYOZeFmffH+Wn8pT/INfuK3UnGmG0dmjZtANy/auOoUKdGDTIjQvvTm06tNtEa9KZ17Z3nfrbF4 tz2tamgAOZYDrSQwW6Yyrei1WkrdP8rAMI9q313j5RhMfZqYoibqlrUfZLaXutq6HVuq/Hp7QjE sU/XgCyofH4+FoWrB9PP7p8tVr5xUtpI8DAmepl7L0daiggmOGWMmtXL+8N3t5ldB6c9kGSgGWC 057PKUy98e+dWpgBDqwblyfLYv4= X-Google-Smtp-Source: AGHT+IGrrsRGguzX4/kC9e3WbImEbwjJYkssRqZLd/MaXcXo9vuO99w70AQRek1qfCCOe8z6Xfj60rV3JfQiJjb4sBg= X-Received: by 2002:a05:6102:2ac3:b0:5db:e373:f0af with SMTP id ada2fe7eead31-5e1de4fa7b7mr972398137.31.1763739507364; Fri, 21 Nov 2025 07:38:27 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 21 Nov 2025 17:38:15 +0200 X-Gm-Features: AWmQ_bnRSECB-QNV5ajAUWklka-n_vfMSfbtfANxXxOZxaF9CvgGnR6DIS32OHA Message-ID: Subject: Re: [PHP-DEV] [VOTE] True Async RFC 1.6 To: Rob Landers Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) Hello > Without well-defined suspension points, literally all code is unpredictab= le. This is what people have been trying to tell you for the last several w= eeks. How can I know when the code will yield to the scheduler? > How do I reason about it? The foundation is there in the RFC and the code= , but it needs more definition and guarantees. What guarantee does suspend() give? You can still break the code with it. I understand what you=E2=80=99re talking about, but I don=E2=80=99t see= a big difference between situations like these: ```php // --------------------------- // 1. File get contents suspend inside PHP CORE // --------------------------- $data =3D ['value' =3D> 1]; $content =3D file_get_contents('http://example.com'); $data['value'] =3D 2; // --------------------------- // 2. Asynchronous version special API // --------------------------- $data =3D ['value' =3D> 1]; // Yes we know about this here. $content =3D file_get_contents_async('http://example.com'); $data['value'] =3D 2; // write happens after resume, timing is different ``` I understand that you are trying to say that if `file_get_contents` is blocking, then there is *slightly more chance* that the code won=E2=80=99t break. And if `file_get_contents_async` is explicitly non-blocking, then the programmer will have to rewrite the code. But which is cheaper: 1. Rewrite **all** the code? 2. Or rewrite **only the code that uses shared memory**? And at the same time, using `file_get_contents_async` does **not** save the programmer from mistakes. I can already imagine a situation where a programmer, trying to adapt the code for async, simply renames the functions hoping it will =E2=80=9Cju= st work=E2=80=9D :) No. It's not! This approach: * Increases the amount of refactoring * Does not protect you from errors > The foundation is there in the RFC and the code, but it needs more defini= tion and guarantees. There is another approach. You can use a special `async` attribute for functions that support it. This would allow not only highlighting the code in the editor, but also validating it with static analysis. In transparent asynchrony there is a rule when writing code. Only code that makes no function calls at all is considered guaranteed safe= . Any call is potentially treated as a hypothetical yield point. I use the same mindset when writing highly reliable code. I imagine that it can crash literally at any line. The principle here is similar. Asynchronous code in this sense is always divided into two major parts: 1. code that accesses shared memory 2. code that does **not** access shared memory You only need to be careful in the first case. Everything else requires no special attention. This leads to other principles: 1. Shared state should only be passed when it is truly necessary. 2. If an object can be made immutable, it *should* be immutable. 3. If an object must be mutable, then it deserves double attention. Above these principles there is one more, the most important: * if you can avoid writing asynchronous code, you should avoid it > Global state is a core part of PHP, like it or not. I love the global state. I=E2=80=99m not one of those people who shout that some approach is =E2=80=9Cbad.=E2=80=9D Global state is great. The only question is how and when to use it. So... summary: Coroutines require: 1. A framework that can work correctly in an asynchronous environment. 2. A different mindset for framework and library developers. 3. More knowledge from regular developers =E2=80=94 a bit of a minus=E2=80= =A6 and a plus at the same time. 4. Strict memory discipline for everyone. Hooray! This is the future of programming. You can=E2=80=99t run away from it. I=E2=80=99m confident that PHP can be adapted for more convenient memory handling. There are possibilities for that.... at the syntax level and at the helper-object level. This still needs discussion. P.S. If someone ever writes documentation, these would be excellent phrases for = it :)