Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128914 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 BB5391A00BC for ; Wed, 22 Oct 2025 22:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761173787; bh=+MZeAdNxwDhoEt0RvYEyaIMGe+XTKZQhMfIOq7MuMLY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=KOj6RwOxz7sETOlkjj/HAoA9aGWIH27IYnYmifOQ+wpyRjiRoLOFxRfqj2+V+jDFm qYNrgrqmp+ZNsGkGR26uozTjUcs9au4FGNdIFQBeQjcgn5hDVkkWSxeAKi1J2nXxys 2KyvLBYqfqjzD83+cCe4dGP4C/xm9uYfUpdT9UOMzF+HrtxyCzoOX7ukFL3OORGQyv NEbwgE+XK/js6Qoy0VL5WP/vLVV7YSbfA9ZedRiLUYHZm9jSTSMEtIKo9GqjGFK6Rd 8W3qZNDOMBU/2A1cuXuW/c2W4nFLg1SoRenQsgLD7W9rXY1dkpguOo5J35tygmL/XH iNsEcT8C8fdFw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA50C180057 for ; Wed, 22 Oct 2025 22:56: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_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 ; Wed, 22 Oct 2025 22:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zort.net; s=zort; t=1761173780; bh=+MZeAdNxwDhoEt0RvYEyaIMGe+XTKZQhMfIOq7MuMLY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=KdI4HP9+cWOLEUpRRY0yPu2X/WXX5r8w4/8KCPup7asbFgIV1oODic/0PSMuvRakM KmCbAzSJSAMtjJyDgKvRBzNVJVxbbC/7Oaju4Od1t/sIyJeKpgG4+otfbwp5xCVuHs qoHMXPe3cpyUQUgvCNVzrZdoFUTdiNo/0HUoJ5eU= 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 F3134130052A; Wed, 22 Oct 2025 18:56:19 -0400 (EDT) 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 4 In-Reply-To: Date: Wed, 22 Oct 2025 18:56:09 -0400 Cc: Rob Landers , Aleksander Machniak , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <0e4e39d6-9cc9-4970-92e0-2463143b4011@app.fastmail.com> <37180d8d-85b4-49a3-a672-334bf4329470@app.fastmail.com> <2f8524a7-dea2-4fbf-933a-c538d3706253@app.fastmail.com> <151800a7-1094-49bc-8e43-c593a74741af@app.fastmail.com> To: Edmond Dantes X-Mailer: Apple Mail (2.3826.700.81) From: jbafford@zort.net (John Bafford) Hi Edmond, > On Oct 22, 2025, at 15:43, Edmond Dantes wrote: >=20 > Hi >=20 >> * Is TrueAsync intended strictly to enable concurrency without = parallelism (e.g. single-threaded cooperative multitasking)? >> Is there a future path in mind for parallelism (actual simultaneous = execution)? >=20 > In short, it mostly depends on the PHP core. TrueAsync itself could > support multithreading. > At the moment, achieving a fully multithreaded PHP seems extremely > complex and offers very little benefit. > In other words, the cost-to-benefit ratio is close to = =E2=80=9Cirrational.=E2=80=9D >=20 > If you=E2=80=99d like, I can elaborate on this idea, though probably = not in this thread. To be clear, since I didn't explicitly state this, my point is that I = would like to see whatever gets introduced by any RFC (as this one is) = that is likely to be used as a stepping stone to full multithreaded = async PHP (whether or not we think that such a destination is likely on = any practical timescale) _NOT_ get in the way of that destination. That = is, I don't want us to go partway down a path, only to find later that = we can't make it to the destination because of a bad or incomplete = decision early on. Which is why I'm asking about stuff that might not be = in scope for this RFC, because it _will_ be in-scope for some future = RFC, and if we wind up with a bad interface now, it makes that future = RFC's job unnecessary harder. And since this isn't going to be shipping = to any end-user for at least another year, we have _plenty_ of time to = make sure we get the interface right. >> * Rob Landers brought up the question about multiple-value = Awaitables. >> I agree with him that it is a potential footgun. If an Awaitable is = going to return multiple values, then it should implement have a = different interface to indicate that contract. >=20 > It seems to me that this discussion has gotten a bit tangled: >=20 > 1. Functions like awaitXX are not part of this RFC, yet we=E2=80=99re > discussing them. Is that really necessary? I can't find where this `awaitXX` function is defined, so I can't = comment on that. But I didn't bring it up, so I'm unclear why you are. > 2. Awaitable objects do not return multiple values. So you say "Awaitable objects do not return multiple values." but the = description of the Awaitable interface says it allows for that. Unless = I'm misunderstanding something, I don't think that makes any sense. And = also you seem to be saying that some objects are Awaitable, and also = there's an Awaitable interface that means something different, which is = definitely going to cause confusion. > 3. The Awaitable interface is basic for others, just like in many > other programming languages. And for some reason, it=E2=80=99s not = considered > a problem there. > So far, no real example has been found where this would actually be a = problem. This may not be your intention, but to me it feels like you're just = dismissing Rob and my concern, which is that single-value and = multiple-value are two completely different beasts and PHP shouldn't = allow you to just casually mix them without throwing a compile-time = error. Rob has provided an example where this _is_ a problem. And Swift does recognize this as a problem, that's why if you want to = iterate on the result of an asynchronous stream of values, you use an = AsyncStream, and not a Task/Coroutine. (Granted: the stream's values = might be sourced from within a Task, but that's an implementation = detail. And why there's also a TaskGroup if what you want is to spawn a = one async task per item in an iterable and iterate over the results as = they complete.) (btw, if you haven't read through the Swift Evolution proposals for = structured concurrency, I highly recommend you do, if only to see = what/how Swift has chosen to do. And then what they got wrong and the = hoops they jumped through to try and remedy it afterwards, some of which = many people here would find quite distasteful.) >> For cancellation, I'm confused on the resulting value. > Thank you, that=E2=80=99s a great catch!!! > I need to check this case. >=20 >> For clarity, the case when exit/die is called outside of async code > In TrueAsync, there is no longer any non-asynchronous code. Everything > is a coroutine. > Actually, that=E2=80=99s not entirely accurate, but it=E2=80=99s fine = to think of it that way. Then, just saying, this is a place where people are going to be = confused, and it needs to be stated clearly. The description in "exit = and die keywords" section shouldn't be under cancellation policy, and = shouldn't special-case being called within a coroutine. If exit/die = still immediately terminate execution, then there should be no confusion = about that. >> I think Async\protect() and forcibly cancelling coroutines beyond = calling $coroutine->cancel() should be removed. >=20 > If PHP were a language for spacecraft or airplanes, where extremely > high reliability is required, this might make sense. > However, the current model allows for more concise code and has > already proven itself well in other languages. There may be a misunderstanding here. I'm not saying you should remove = cooperative cancelation. That's perfectly fine and should stay. With = cooperative cancellation, it's not necessary to assert you're in a = critical section, you just ignore the cancellation signal and keep on = processing. What I'm proposing that specifically Async\protect() and = *forcibly* cancelling coroutines should be removed. (You'll note that in = some multithreading APIs, forcibly terminating threads, while allowed, = is very much discouraged because that can leave things in inconsistent = states that causes future crashes or unpredictable behavior.) > I actually have a stricter explanation for why the cancellable model > is more advantageous than any other. > This particular model fits well for read operations, which are usually > as frequent as, or even more frequent than, write operations. > Therefore, this approach simplifies asynchronous code while keeping > the overall risk low. The RFC should include a description of _why_ cooperative cancellation = has been chosen. > Thanks, Ed -John=