Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129235 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 B31BE1A00BC for ; Sat, 15 Nov 2025 17:22:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763227346; bh=Aliv8HIB6n5txdILR9zcUT9vv9aEmv/g4vdduL19Zhk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AqLF5HQfY1OKCTBO84g2UA+x9yah7QmJzJcLHo/vdlEur2Cwsn68MGEuCbFCDHx1x oCq2NVb2PQd8f5bzdnhpGRa0RkjhSmd/Bcj9ySt203TIAPakSnffamNaxkiHHYJRB4 a4k8nfwljBiMQYJxreYPTN06AsjZGvX+alsMJ8cFrafUSFTXDD9mc5BGSYBwRlWSZg vs5Fwo+bG9ToCe9ngN1WhY2O/RJS+DLdbt8nroOAlh0PqYaXMw6lBbbrTdfaLpZQJ0 Gy96dNSne1j9g8v4g93lMBR85/AGb7NatP74jHOXoJaQsPgkdihtGUDhBfT1RhTNJS rzq/l93UkesPw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9996E180086 for ; Sat, 15 Nov 2025 17:22:25 +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-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (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 ; Sat, 15 Nov 2025 17:22:20 +0000 (UTC) Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-5dbdb139b5bso2612098137.2 for ; Sat, 15 Nov 2025 09:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763227335; x=1763832135; 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=Wd+W7w3RI0ItJWB6vyAgxRqsbCIFXdn8c1wLUu814Ok=; b=HLNoCAPJmifBuidaBgxichdCtis8A1p5Fkp73Mu95rp1hHt1ajhYBHiAsh+TWlz7VR tFp8PuZEquV5pJz4wT3LYwjyOgFJA3e2ENgvt/2Nqzp+9THzXob1xW1LHxIByvvwwSUt DewvkGlhhC2oMm/62t9Fqku3zwq+t+3UWTxU6aoyqArLPsdpzoWiAC9Lh33FCkMfLzCH 0jEnlilLM+gV3Ir2D6B2syh1Zq8AYEgmS+ezwk6YdYxAd+Ir9LTo/uqd7kXWHeQ425N4 aFeSld5JrQVJ0gtObmIZUU9xy/mkMSz0eeSiPynP5c/0Lt/7ERlnabDbSzPjixCZB1BD /u7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763227335; x=1763832135; 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=Wd+W7w3RI0ItJWB6vyAgxRqsbCIFXdn8c1wLUu814Ok=; b=WlrGaZNCpRZkMtj/zIPzRUJmKUhEWBKCmmPOaKlZA4NobmtBFp4WMkHpfXj9FcuhDf ZOVOyr5HX41SbeYgr10Jpmkwzb7+jut7RpreaiEdnx4V5BCw8X4s/zxy9YY93JWPaWJJ /4OGGoKb2mCwG9mkoxPVBShd9dPQcc42k9DxMQCSIK+nSuS0Emn3O1x51A4BNZFjgjpE g2LFtijRDuWXmE/0oWvwR3vUTBYc8jsSeqJKDuyOnpQ+xqaXrtj1xe6tUUsQaDNDInNH UuYEQcWs7B2v57kMTPzo+SX+nLlQAXxFLIgTC16KIFF6BiTHm7yrAGb08cSa+cf9+3/9 udEw== X-Forwarded-Encrypted: i=1; AJvYcCUT0vP8Ouql25Q9OYUDBdU16mjuecFYGQ5Nph+42R5iSHiiTtuH/iBuxKACpo2Tm9E6c+Njqw86KLA=@lists.php.net X-Gm-Message-State: AOJu0YxfwRRhT4FXhMXKuwp5Lk01F4ayU7qdnP8o6RCogBRNhXwMl+EO LOUZFEyuzw2zEsC5RqZ/iYuPZ4eea30LVNRLIyI4NytWN2dke6d+hyacHKHLjXXPAP5JgVsEMU3 OHYnXzFj99tMckYjmACcNmltLCdQwD7o= X-Gm-Gg: ASbGncvGWWF8pXSoHjHvBJOVm3ZBFtCM4VpcR6w7BE021j3tc6cOQ+mLjpHxecCivA2 fuHrgLKTeM7KHUZotCLOSqareuxvw0Vkyhx72PJtbVGf5ScuGZAlBXSaS9KR2j4k0kUBUOLKFAy buqoGM1SG+CthtMXKZztir8QlZqq8q+CGNWBq78bFKEwsbifLwb3RMeFMfTBYWH4smJrdAr5AzJ KudvRkSjqLZKlzpG8oEptXY02SkK5a5leTnRQOCGK8rASB7LT4j7y6y8SgBke8GB0eXe5wX38m7 KxZkcit4wubzXqkyhA== X-Google-Smtp-Source: AGHT+IElquMo0ae9ApcNzxgxtCHCJAtwfoXVZpNxy3sARYmVQu9bdvv9D/4MgBHfeuC/CAsn1bCrgQzUeLZ3x9ry638= X-Received: by 2002:a05:6102:94b:b0:5db:ef7e:8dc9 with SMTP id ada2fe7eead31-5dfc5651308mr2875567137.22.1763227334648; Sat, 15 Nov 2025 09:22:14 -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> <12D52EE4-62F4-42AC-A17D-A8F3A19D2433@zort.net> In-Reply-To: <12D52EE4-62F4-42AC-A17D-A8F3A19D2433@zort.net> Date: Sat, 15 Nov 2025 19:22:03 +0200 X-Gm-Features: AWmQ_bkBFBGEaZGIveulryUihbGP2dgS4hEQG9t3gASGr-C22O-GcaD6mT9Dlok Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC Stage 5 To: John Bafford Cc: Rob Landers , php internals , Jakub Zelenka , Larry Garfield Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) > To provide an explicit example for this, code that fits this pattern is g= oing to be problematic Why is this considered a problem if this behavior is part of the language=E2=80=99s contract? Exactly the same way as in Go for example, this is also part of the contract between the language and the programmer. > $this->data can be changed out from under writeData(), which leads to une= xpected behavior. So the developer must intentionally create two different coroutines. Intentionally pass them the same object. Intentionally write this code. And the behavior is called =E2=80=9Cunexpected=E2=80=9D? :) > that it is working "exactly the same" with coroutines by ignoring that it= is now wrong I understand that a word written by one person can be interpreted however another person feels like. Language is not a reliable carrier of information, so people must take context into account to extract useful information with minimal distortion. The changes described in the RFC refer to the algorithm for handling I/O functions in blocking mode. And of course these words assume that we haven=E2=80=99t lost our minds and understand that you cannot write completely different message sequences to the same socket at the same time. In practice, changes are of course sometimes necessary, but throughout my entire experience working with coroutines, I should note that I have never once run into the example you mentioned. Even when adapting older projects. And do you know why? Because the first thing we refactored in the old code was the places with shared variables. > There is no way in general for code written without coroutines or async = suspensions in mind to work correctly if it can be suspended. Agreed. A developer must understand that potentially any function can interrupt execution. This is a consequence of transparent asynchrony. It is both its strength and its weakness. I will repeat it again: not some specific function, but almost ANY function. Because under transparent asynchrony you can use suspend() inside any function. This does not negate the fact that documentation should list all functions that switch context, but a certain coding style encourages this way of thinking. Modern programming languages strive for clarity and cleanliness. In other words, colored functions provide code clarity and prevent errors caused by misunderstanding what a function does. Critics of colored functions criticize them precisely for what is actually their strength, not their weakness. Color is an advantage. But in PHP, colored functions are inconvenient. Overloading I/O functions does not lead to serious errors that make developers suffer; on the contrary, it saves time and gives the language more flexibility. I can explain why. The amount of code that works with sockets in PHP is generally several times smaller than the code that works with databases. In other words, the modules where such errors could occur are simply not that many. They do exist. library clients... but compared to all other code, there are far fewer of them. And as it turns out, refactoring them for coroutines requires very few changes. Especially if the code was already well-written with best practices in mind, then it will most likely work excellently with coroutines with minimal adjustments. How did we refactor old code for coroutines? 1. We took the modules that had global state. There were not many of them. 2. We used a Context, which is essential, and moved the global state into the context. I don=E2=80=99t remember exactly how many thousands of lines of code there were, but definitely more than 20,000. But why anyone would intentionally pass the same object to different coroutines and then complain that the code broke. I have no idea who would need that. :) A developer should strive to minimize asynchronous code in a project. The less of it there is, the better. Asynchronous code is evil. An anti-pattern. A high-complexity zone. But if a developer chooses to use asynchronous code, they shouldn=E2=80=99t act like they=E2=80=99re thre= e years old and seeing a computer for the first time. Definitely not. This technology requires steady, capable hands :) Best Regards, Ed.