Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129234 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 215461A00BC for ; Sat, 15 Nov 2025 16:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763223672; bh=lA/yH00SQHOj8WsQNSh+VjrOw9p1uJhRKLzQbzWtodY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=l/MqMHwi7JtJGylSp2VJCnr9gYXfKRB0dettjSb5GMzV/3r1Nwm/1+BJ8zsh3vMXx +bgrg8sMwtUrMKJbPzu8Rhie3+LYvhyzQaZpxhKAtUFzpQr4uZk+EvBy0rCTTann75 gcB6P8LfqFZOmbBN4ppe8X2Wiad84BX0IjqSGrBaXytlav1u7kOrbYUJ40yGJOjhTA oSrfZDxyZ0Y0IbNBRExxZ+88v+JVp6xmOLziy9ckpA5pqgPK2BItfgbTeCQs+tQRxM SSbWKRSpwoMVqCxI6v3NCU8wFlBCzCe4AMfbg4lTcDYZI3lIrO/1UUR8FzLvK79AY+ dByenhXqcBGxg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0D0FF1801EA for ; Sat, 15 Nov 2025 16:21:12 +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_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (nebula.zort.net [96.241.205.3]) (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 16:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zort.net; s=zort; t=1763223651; bh=lA/yH00SQHOj8WsQNSh+VjrOw9p1uJhRKLzQbzWtodY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=OjmfOV30dXH6jR9PnbSIshicYRCKfaPuaoOfQvf2lSoKrVoOE9uZW/mH6ncLyeqKT QIBk8HcjYmKkHL0JpwfjXjg2tWx3RAqt6kpKV0MIZLyjLbEhGE7JxPUdcpk9Y5k4OC CjDJk35J2KMn0GpCWvQr4aCNbcPMbwVDy7Wv7Z44= Received: from smtpclient.apple (pulsar.zort.net [96.241.205.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id 77EC51300460; Sat, 15 Nov 2025 11:20:51 -0500 (EST) Content-Type: text/plain; charset=utf-8 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PHP-DEV] PHP True Async RFC Stage 5 In-Reply-To: <6618a91c-5393-4f40-88b5-b5041ee09deb@app.fastmail.com> Date: Sat, 15 Nov 2025 11:20:41 -0500 Cc: php internals , Jakub Zelenka , Larry Garfield Content-Transfer-Encoding: quoted-printable Message-ID: <12D52EE4-62F4-42AC-A17D-A8F3A19D2433@zort.net> References: <6618a91c-5393-4f40-88b5-b5041ee09deb@app.fastmail.com> To: Rob Landers , Edmond Dantes X-Mailer: Apple Mail (2.3826.700.81) From: jbafford@zort.net (John Bafford) Hi Rob, Edmond, > On Nov 15, 2025, at 06:37, Rob Landers wrote: >=20 > I have concerns about the clarity of when suspension occurs in this = RFC. >=20 > The RFC states as a core goal: >=20 > "Code that was originally written and intended to run outside of a = Coroutine must work EXACTLY THE SAME inside a Coroutine without = modifications." >=20 > And: >=20 > "A PHP developer should not have to think about how Coroutine switch = and should not need to manage their switching=E2=80=94except in special = cases where they consciously choose to intervene in this logic." >=20 > [...] >=20 > With explicit async/await ("coloured functions"), developers know = exactly where suspension can occur. This RFC=E2=80=99s implicit model = seems convenient, but without clear rules about suspension points, I=E2=80= =99m unclear how developers can write correct concurrent code or reason = about performance. >=20 > Could the RFC clarify the rules for when automatic suspension occurs = versus when manual suspend() calls are required? Is this RFC following = Go=E2=80=99s model where suspension timing is an implementation detail = developers shouldn=E2=80=99t rely on? If so, that should be stated = explicitly. Keep in mind that Go didn=E2=80=99t start that way and took = nearly a decade to get there. Earlier versions of Go explicitly stated = where suspensions were. >=20 > =E2=80=94 Rob To provide an explicit example for this, code that fits this pattern is = going to be problematic: function writeData() { $count =3D count($this->data); for($x =3D 0; $x < $count; $x++) { [$path, $content] =3D $this->data[$x]; file_put_contents($path, $content); } $this->data =3D []; } While there are better ways to write this function, in normal PHP code, = there's no problem here. But if file_put_contents() can block and cause = a different coroutine to run, $this->data can be changed out from under = writeData(), which leads to unexpected behavior. (e.g. $this->data = changes length, and now writeData() no longer covers all of it; or it = runs past the end of the array and errors; or doesn't see there's a = change and loses it when it clears the data). Now, yes, the programmer would have to do something to cause there to be = two coroutines running in the first place. But if _this_ code was = correct when "originally written and intended to run outside of a = Coroutine", and with no changes is incorrect when run inside a = coroutine, one can only say that it is working "exactly the same" with = coroutines by ignoring that it is now wrong. Suspension points, whether explicit or hidden, allow for the entire rest = of the world to change out from under the caller. The only way for = non-async-aware code to operate safely is for suspension to be explicit = (which, of course, means the code now must be async-aware). There is no = way in general for code written without coroutines or async suspensions = in mind to work correctly if it can be suspended. -John