Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129370 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 5F8441A00BC for ; Fri, 21 Nov 2025 14:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763735651; bh=RX5LlMZBrhKydS1yv4puZlYrTAhYQ7vU6wCfPZLVXBI=; h=Date:From:To:In-Reply-To:References:Subject:From; b=VsMsPLleIn1baCmroaj5WzpDj0lKI400stmb6RYRu0idje5+dvQ4MBegj71aFqbVh tVLjstkYQNfsuDrYm1RsiGiw+TYgveaoNQksMkj8xROBzg57zestN6I4mJ+Sqov1Y2 GonzC7i9sJ9Nqt/2tGcgTIkeuahqmCkKqqZYdlpJtotpeNiqJe8xIYqtGNIxUCGk2f BJhyflKKcEm+/llzjtJPa1DpmLXRjdC/0aGoEr0IKbUA8a6X6OtU91+Vm98fE2VirN /ALE+xvXqqnUt3WD2Rnq9Y0Ctv9Jqwf03sQNdgdS1bVHvDUROZFhBNiObKbkNdjOj/ GLcIqcnJ5Na2g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BAAA01804E4 for ; Fri, 21 Nov 2025 14:34:10 +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.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-a6-smtp.messagingengine.com (fout-a6-smtp.messagingengine.com [103.168.172.149]) (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 14:34:10 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 2A1E7EC01A8 for ; Fri, 21 Nov 2025 09:34:05 -0500 (EST) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Fri, 21 Nov 2025 09:34:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1763735645; x=1763822045; bh=RX5LlMZBrh KydS1yv4puZlYrTAhYQ7vU6wCfPZLVXBI=; b=RvUlO5bbGjTLjImWJoL6aZDthP nXRSqmmlk1KacvZBWNVlFRrplm2AJ3w/JwVcHq55PG/t8j9YK/DA+wHPuh9md1Uj CJl2hpk2XoZSs2WJ/E6oe64vnVOAYKdB0zrCAKBNo0yrzjBv92zCsK1JHzfKavs5 jbDu2aMhqHm9F5RPFBfXMRjv2B5tRnGgvWSZem5VoYzTunDlV7/Jqr5gsSvt+zJ3 LCZg3V14LrdTiJQIoRgJLRXA7RHHcix46QxG62O0N2dZHsg/+BpTQWeYuXNTA/GR JElCQKdZev7kpZ+3LF/OTAy4Ig+qSQMX9QdNidQHvQfhy/3NK6xNPvfSfTvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1763735645; x=1763822045; bh=RX5LlMZBrhKydS1yv4puZlYrTAhYQ7vU6wC fPZLVXBI=; b=AhqGo5gZZAOPuv5PHIDfK5k1WlIA3Tc4YjSjrZzNnJ3vqd5Ltzg rIMza25wD5ttStfwuuBvCM+uvji2+w/F4t4HVoIbcrfUExQbgqCAo+EGDnefeig6 4rTeGwlrpYDqcYrJZH8UVC1J+dl+bkQjpyh9GaoGWtbjd0VlSPoptpaR9RwWHucX fWnFIDioAzjAd46OGGJlNoINyVnWefcXYf0iR83wzZl7bY3hVdoKr+uxy1DcUyqL 4XNEZYBjxC/45eXAPLj9sQwuRj0zSXsxtvgUT6pMNDaNSdoYPUIraNpsLJNtkeeN DzrkjL9Wmu/2lNjuDLWU8nd3/SivFIOsYbA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvfedtvdduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvkfgjfhfutgesrgdtreerre dtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggu rdgtohguvghsqeenucggtffrrghtthgvrhhnpeffheehffduveehgfdvgfeghffhtddtje duieetkedvkeelgeegkeektedthfduffenucffohhmrghinheprhgvvhholhhtrdhruhhn necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosg essghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhht phhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 99FE81820074; Fri, 21 Nov 2025 09:34:04 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AfNtV4qggFeZ Date: Fri, 21 Nov 2025 15:33:43 +0100 To: internals@lists.php.net Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [VOTE] True Async RFC 1.6 Content-Type: multipart/alternative; boundary=579c8032fb9b442e84494e06ebf558a6 From: rob@bottled.codes ("Rob Landers") --579c8032fb9b442e84494e06ebf558a6 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I'm not sure why the To/CC list got so long. Please reply to the list, n= ot to each person... On Fri, Nov 21, 2025, at 14:45, Edmond Dantes wrote: > Hello. >=20 > To use AMPHP you don=E2=80=99t need to run its server. But let=E2=80=99= s simplify the situation. >=20 > You have Fiber. > With Fiber you can build an EventLoop + Scheduler, create two > coroutines, and then run code inside them that, for example, renders a > template. >=20 > It will require a fair amount of code, but it=E2=80=99s possible. > At the same time, ob_start/ob_end will immediately break, because they > don=E2=80=99t support Fiber switching. This is a known bug. > And if you pass global state into closures, and that state changes > unpredictably, the application logic will essentially break. I don=E2=80=99t know why you=E2=80=99d build all of that from scratch. h= ttps://revolt.run/ will allow you to run amphp/reactphp in any request. = It "just works" You do need to consciously kick off the event loop, though, as well as i= nstall some specific extensions, or you=E2=80=99re stuck with the stream= _select implementation, which isn=E2=80=99t the best. That being said, the only problem you=E2=80=99d run into trying to insta= ll this in a WordPress plugin is if *any other plugin* is using Fibers o= r another Fiber library. From experience, they don=E2=80=99t always play= nicely together, and there should only be one event loop running at a t= ime. > **What=E2=80=99s different with TrueAsync** >=20 > 1. You don=E2=80=99t need to write a lot of code. Yes, just spawn(); > 2. `ob_start` and `ob_end` will work correctly. > 3. If closures share a variable that multiple coroutines write to > unpredictably, the application will still break. Without well-defined suspension points, literally all code is unpredicta= ble. This is what people have been trying to tell you for the last sever= al weeks. 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, b= ut it needs more definition and guarantees. > In other words, no matter how asynchrony is implemented in PHP (and > other langs), it will always require correct handling of shared > memory. > And I want to clarify a bit. This is not about a global variable. It=E2= =80=99s > about shared memory. These are not the same things. A local variable > can be passed into a closure by reference. > But if you don=E2=80=99t call WP() inside a coroutine, nothing prevent= s you > from using asynchrony. PHP is full of shared memory, even applications. Take, for example: $val =3D $this->cache->get('key') ?? $this->cache->set('key', 'value'); Currently in PHP, this is unsafe if the cache is a proper cache (like me= mcached/redis), but for an in-memory implementation, it=E2=80=99s effect= ively a Check-And-Set. If the cache is implemented as async, then it bec= omes unsafe even for in-memory implementations. This may-or-may-not be d= esired. However, this gets weird, very quickly, very fast. $_SERVER/$_REQUEST/$_= ENV/etc are all global memory that usually doesn=E2=80=99t change. Howev= er, frameworks change it all the time, to inject environment variables f= rom .env files, to sanitise inputs, etc. Swoole avoids this by having a = Request object. This is simply not present in PHP. Global state is a core part of PHP, like it or not. =E2=80=94 Rob --579c8032fb9b442e84494e06ebf558a6 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
I'm not sure= why the To/CC list got so long. Please reply to the list, not to each p= erson...

On Fri, Nov 21, 2025, at 14:45, Edmond= Dantes wrote:
= Hello.

To use AMPHP you don=E2=80=99t need to r= un its server. But let=E2=80=99s simplify the situation.

<= /div>
You have Fiber.
With Fiber you can build an EventLoo= p + Scheduler, create two
coroutines, and then run code inside= them that, for example, renders a
template.

It will require a fair amount of code, but it=E2=80=99s possible= .
At the same time, ob_start/ob_end will immediately break, be= cause they
don=E2=80=99t support Fiber switching. This is a kn= own bug.
And if you pass global state into closures, and that = state changes
unpredictably, the application logic will essent= ially break.

I don=E2=80=99t know = why you=E2=80=99d build all of that from scratch. https://revolt.run/ will allow you to run amphp/= reactphp in any request. It "just works"

You do= need to consciously kick off the event loop, though, as well as install= some specific extensions, or you=E2=80=99re stuck with the stream_selec= t implementation, which isn=E2=80=99t the best.

That being said, the only problem you=E2=80=99d run into trying to inst= all this in a WordPress plugin is if any other plugin is usi= ng Fibers or another Fiber library. From experience, they don=E2=80=99t = always play nicely together, and there should only be one event loop run= ning at a time.

**What=E2=80=99s different with TrueAsync**

1. You don=E2=80=99t need to write a lot of code. Yes, = just spawn();
2. `ob_start` and `ob_end` will work correctly.<= /div>
3. If closures share a variable that multiple coroutines write= to
unpredictably, the application will still break.

Without well-defined suspension points, lit= erally all code is unpredictable. This is what people have been trying t= o tell you for the last several weeks. How can I know when the code will= yield to the scheduler? How do I reason about it? The foundation is the= re in the RFC and the code, but it needs more definition and guarantees.=

In other words, no matter how asynchrony is implemented in PHP (and
other langs), it will always require correct handling of shared
memory.
And I want to clarify a bit. This is not abou= t a global variable. It=E2=80=99s
about shared memory. These a= re not the same things. A local variable
can be passed into a = closure by reference.
But if you don=E2=80=99t call WP() insid= e a coroutine, nothing prevents you
from using asynchrony.

PHP is full of shared memory, even ap= plications. Take, for example:

$val =3D $this-&= gt;cache->get('key') ?? $this->cache->set('key', 'value');

Currently in PHP, this is unsafe if the cache is a = proper cache (like memcached/redis), but for an in-memory implementation= , it=E2=80=99s effectively a Check-And-Set. If the cache is implemented = as async, then it becomes unsafe even for in-memory implementations. Thi= s may-or-may-not be desired.

However, this gets= weird, very quickly, very fast. $_SERVER/$_REQUEST/$_ENV/etc are all gl= obal memory that usually doesn=E2=80=99t change. However, frameworks cha= nge it all the time, to inject environment variables from .env files, to= sanitise inputs, etc. Swoole avoids this by having a Request object. Th= is is simply not present in PHP.

Global state i= s a core part of PHP, like it or not.

=E2=80=94 Rob
--579c8032fb9b442e84494e06ebf558a6--