Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129278 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 86EDF1A00BC for ; Mon, 17 Nov 2025 09:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763372972; bh=STmP/IX4Jn/U5FJegeqVgat0lcmA6JXpkZbAEp82iOc=; h=References:In-Reply-To:From:Date:Subject:Cc:From; b=jsZ8pbkZlRlI7n7cN1vjTn1qObRVBXzyPKSBf6iLECtdk53CurduCTb/zW7CGOmjZ fkhHiU6ax9M6TctkeFTN4OGS6BTE+O5VfhMCz7GLSLKvrW0szZWFXrb6W/yvtCccJT FvuTKI140Hq1H378qleBa933mj6IwuIqTI9xmQWBqEbfnuLcTi6WT91bt69KxF9wa6 hwVyYpN5ZyccLN6BG4VZMyxg/9tAQFaj3z3uaEbVFKq7uQyL0rOI1IUjMeV+WE8/GW FAsgziPJ/ESfDWqenRSPS1NrlTDPCZMqgvkdSSr3kWeKCe1U+fHGkjNyRSCF84ViPZ jWBxltkrfpYbw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 38884180041 for ; Mon, 17 Nov 2025 09:49:31 +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=4.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, MALFORMED_FREEMAIL,MISSING_HEADERS,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 ; Mon, 17 Nov 2025 09:49:31 +0000 (UTC) Received: by mail-vs1-f51.google.com with SMTP id ada2fe7eead31-5dfd380cd9eso1585893137.2 for ; Mon, 17 Nov 2025 01:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763372965; x=1763977765; darn=lists.php.net; h=content-transfer-encoding:cc:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nCQAzb3E5tBCLUAfMrKa6UWgxLAbj3+OKKJyL0Ipq+4=; b=DAgiyNzwnuoLmtuKRf0LmfnFNTH4PFTl0jYozwjRR8d0M0Zor2MOYi4wN7UM3KEU6C zXocpzDvfRy2JQ5e8PoMMPbvYa44VZsAaYuPj+ZTAQdJ/7E/Hbatgm5QcIeyEZbtbiYN JNqLsPPDVQfzWum1Jq/X/7+DSaIU0awtrng+TtLtln6YoUy8mZQ0EYaYeLz2LL/6dW/d dNFRJm8d9xst+eLKkvA3Wmsy4Oa7Zczetst1qPV3xbX65Ve6VC9JVZM7X7KdeNql3k36 ItGZDv6i0LXFEszFeWUtbmyui9h0LG4mi5Ej48qNpvjbxCHjbd/xwS9shM3X/7mzfseq 2+4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763372965; x=1763977765; h=content-transfer-encoding:cc: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=nCQAzb3E5tBCLUAfMrKa6UWgxLAbj3+OKKJyL0Ipq+4=; b=SpDU3mjXfE8LM1HoVtBBfgPvL0z/FWcg8VDzqDisklfNcwnnRhcT6o/P4XuzP31J4D Yx8eOx1KxMHQLcXeZVkz+lQnIx3Gw0ggYejJn4d/wXDaadwntbyBHnchGuMqFIHFUJtr v3z5ClWXWgaLJNp18XWVMbtu7JXUSB8ypA2dn+8N41iMdiNswcVjQZZHB1X7XIYf+/SL NVSxkEL0zhehceGEnjW/B3NN+ieX1FuJcrAi2YHx69UiKpr1X0hmddCXnwGKCV70vU6v RYv3dKiKNEuJgEKWrR/dRz2gFjct++VyHraKdpU5zoCDjNDsYHRgpKh8Xcd3ZCWUG2Ae IlXQ== X-Gm-Message-State: AOJu0YzyRUe5Q8ZhzI4Xrf43LFHu5WutDNPpEfb6i2PksjMwy4vtOEX1 sjvAg/X1afGVMfw9FsRbvt+4rolI9i1jMOP9Wcf56TEeA/2Y/sVr9LdfNSvdNbAlXIyJRxih5Fs uGKx+D6gxMovuziV4KUb6z5wWQ6+vdUEingSp X-Gm-Gg: ASbGncthl0/SBpYaQL4WSTq640iguVJWK07SfrG1B1v4/HX6OOq0YoNd5HQBzMBpiOp S+AOeJzAplPw2nnr/ytV9wUzerNukgNHqnYerzpNrznMDWfD1ae0urWcwVPZRWWaTzqhbz5z6Nd tkR4rPov06wanQj+qXjk2Q+GCOlXajVi9hVKfmiDVX/iDcusA4uECHazB3WQpdTYOdIpmt49nHQ 8LSCV+5O8kM8dMBlQJI0pucLlS8pA/IoCXMfc+HhyO+Wkng9PwhP94a/g9fd8syV1e9JNBoCDDB GSUNVId3wImCQk+JvGUUKGBVLIlS X-Google-Smtp-Source: AGHT+IHz7kFj3u0ZSHrHQPESgQl9rvFKbwqZI4ILulKw9f2diSZeBWfUC5ryJuARZNfc0VjTlVw2M8FcB1LUTx6Ys1s= X-Received: by 2002:a05:6102:330a:b0:5db:1fbc:4462 with SMTP id ada2fe7eead31-5dfc5bc63d8mr3865765137.31.1763372965026; Mon, 17 Nov 2025 01:49:25 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <6618a91c-5393-4f40-88b5-b5041ee09deb@app.fastmail.com> <3e0cf0a1-c1a3-4e05-97ba-0eeb7f559a53@app.fastmail.com> <41c5eed0-dd1b-4ea4-99cf-f6d16682bd7f@app.fastmail.com> <08303459-b4ab-44a8-9795-0fb7f82914d0@app.fastmail.com> In-Reply-To: Date: Mon, 17 Nov 2025 11:49:14 +0200 X-Gm-Features: AWmQ_bnpRcI2YxtB7QjGD4Qct7Le2wJj0Ue5UF5tINKIp9_DNsln5-HCIr-Tfqc Message-ID: Subject: Re: [PHP-DEV] Re: PHP True Async RFC Stage 5 Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) Hello Larry Regarding the phrase about =E2=80=9Cproblems with mutable shared state=E2= =80=9D. In this context, when I say =E2=80=9Cproblem,=E2=80=9D I mean something tha= t significantly worsens development. =E2=80=9CNot a problem=E2=80=9D does not= mean that errors never occur. It means that resolving them takes an acceptable amount of time. This phenomenon has reasonable explanations: 1. Developers usually know where they use global state. And even if they don=E2=80=99t, they know that this is the first thing to check. That helps a lot. 2. Bugs involving shared memory are usually easy to reproduce (which is rare in asynchronous programming). This drastically reduces debugging time. 3. In a single-threaded environment, shared-state bugs are much simpler. For example, the probability of corrupting data structures is relatively low. 4. In PHP projects, shared state is typically used in a small set of scenarios, and these scenarios are usually simple, which also minimizes the time needed to fix issues. For example: some global variable stores a SessionId. And then it turns out that an action was recorded not for the user who performed it, but for another one with a different session. In most cases, the bug report alone already points you directly to where you need to look. My point is not that you should ignore shared-memory bugs, but that you shouldn=E2=80=99t fear them or treat them as something huge. I also want to remind that in programming there are no =E2=80=9Cbad=E2=80= =9D approaches or technologies. Shared mutable state is a very useful thing and should be used. For caching, for storing session data, for access-rights memoization, and so on. You don=E2=80=99t need to avoid share= d state. You need good tools, patterns, and proper practices. As for language-level abstraction, features like `local $var`, effects, and context will help make the code safer. Monads would also fit PHP well, as they allow expressing parallelism better than procedural code. > That's what I think we all want to NOT have in PHP. Exactly. PHP exists to save money, not to spend it. Recently there was an article about Python describing the problems caused by having multiple runtimes. > Third: So my question would be, is there a practical middle-ground? > Is there a syntax and semantics we could define that would cover *most* e= dge cases existing code may have involving shared mutable state automatical= ly Based on the current state of programming languages, there is no good solution. Only radical ones like Actors, Arenas, and so on. All of them rely on complete memory isolation. But that=E2=80=99s not the point. T= he point is that PHP still has legacy code, and you cannot just throw it away. > the RFC right now says "any IO operation, implicitly, hope that's OK." Go does the same thing, and it=E2=80=99s a very convenient mechanism. There is a small percentage of cases where this breaks the logic. Here is one of them: ```php $start =3D microtime(true); $data =3D file_get_contents('data.txt'); $elapsed =3D microtime(true) - $start; if ($elapsed > 0.001) { echo "Reading took too long\n"; } ``` The code breaks only in two cases: 1. When there is usage of mutable shared memory/shared resource 2. When there is logic based on a timer Yes, such code will break inside a coroutine. But should we be afraid of that? I don=E2=80=99t think so. The likelihood of this kind of logic is very low. And if needed, this case can be explicitly documented. Besides this case, special attention is also needed for: * libraries that use sockets * libraries that use threads * libraries that use processes But this does not mean there will necessarily be major or serious problems adapting the code. PHP already has experience with Swoole, and Swoole works exactly the same way as the code in this RFC. For example, adapting the RabbitMQ library for Swoole required changing about 10=E2=80=9320 lines of code, roughly 2=E2=80=933 days of work. Most o= f the time was spent on testing. Regarding the hybrid function-tainting model, it is designed for compilers or static analysis. For PHP, it could be implemented like this: ```php #NoAsync function myFun() { asyncFun(); // Error <--- } function asyncFun() {} ``` This is a solvable task for static analysis.