Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128913 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 389241A00BC for ; Wed, 22 Oct 2025 19:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761162233; bh=T4u87UrEOXxzrCsxvkNS63yHXyXFS36m4gpXL23PbNs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SpahgUIuWaFeM3dW6fSJXbchmAnDnpnn7aHmH1yEEZJJKnlcbL33peYwS+kh80Ck9 28fnq1vDIlOB8aSM3vfNvzwfP8FRvGSk9EYNso1cwsECa0bbfechF1JXcsC4DR9hxq 533sINaHYbc2+tYiLvdWtrxkOOB6+vQf/e1g0EtRMvpvhI+VjnaCOideuagd5IpmKR hNaZYwoH0I6/NAEyqQnfJ+KgSKRM15Pdd0edjuBotf/6/7pTiRRXYPUHLqqW+0s4LW NNnDFLaSVvNr9JwlUEYFImnz2X7jVKMBZuawpakvXKw8no6VNJMRl7U9p6VLDAr9P+ nc2DDhCxCaGeA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B7C581801EE for ; Wed, 22 Oct 2025 19:43:52 +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-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) (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 19:43:52 +0000 (UTC) Received: by mail-ua1-f52.google.com with SMTP id a1e0cc1a2514c-932f654eaaeso1163636241.0 for ; Wed, 22 Oct 2025 12:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761162227; x=1761767027; 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=iFJ9b2j8l3rEpQGNy6bDf8Kv9HFU5cuRMih6XVOAl9I=; b=HBvvT7flhMN8M+bgUWOI/Wwh+wUVR8joLDSbfiv7fUD24YvAqHzYYkp9dCcCCtJ+Cy Ls6TBs3Ioh0bDo29ul1ba0Oma7pf8iT4ZqvoqS+TGuB5vIjAd2X+uL8zv4DHx4zKycYz zAmQcuDeeVtwoCJOuJVlbXFL1sPSC9WkRMF4dPsyxvKANgC8n2KgXqrJS4z+tG4itAQm /KJP/KhGu1HrrmPNzkkXRFVBtfx1v5kF8gXIHB7Vpio5DWF9+kkZNSYf1llKZmaHT1H3 TtJdOldLh7m3UDUCoGcFTQJny1ARgn5BDg86UDGXZ6K2fbnuWiZGr3xJJNIGqAYggwz4 kctQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761162227; x=1761767027; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iFJ9b2j8l3rEpQGNy6bDf8Kv9HFU5cuRMih6XVOAl9I=; b=Y2O/LmL/louoxwI3WWkqexH/xn/mXJ0C87ygRhBlDW9DjaNojfnDdMX9pNN5cyyPyw RcHqglxLz0TZOgBI49a4L62T/e8Z2cWkPkgFcyNa2fz4K31eB7Parl+gKTQphvqdabdQ y5T5agsE0ZMWxuo1uvqQA9gidaCyEE9Rg1HJv7vkdMD4yLJ7oxA1XU1RhjkwalmWF1jF 5NNGnWM8UQZv89309iiabeXlOF8yQk6ILAV6g9t8eQrLadND/1eifA/sIH1xWLNywFn6 XXHKyDFyONXqcB4I3EJMWBO1T9IlgzQOqqiQQXY6Jk7n9cEPPKy3h8KfqQK/Ox9z74nY b7YQ== X-Forwarded-Encrypted: i=1; AJvYcCW67cIBNk3I+YGmVYqM3Ck32snIMdj3KGMWBbj1QYmAywhTFkMZgzI+Q6vUYdbsP9gieECF6KK7OhU=@lists.php.net X-Gm-Message-State: AOJu0YyAHg39baVjjMWCRDWWdIidlk3he8LHcEebqhJOelmHOFwIWQoz 0c622o6nkt2gIWf/6I4PazR1JTu2fTGiZaODcGjmQboxve29RrxiDlkmTChEX7hTnoUtHLh0Dl/ 5j/dyfJlumzWnQ6Jw2TX8W/D61dL+3ImGxsHvvSw= X-Gm-Gg: ASbGncuTI8LK9WtXWUg1RPyFqig+e5VVN8ZXtWS9uLAm9Xh/NyuH7eML5WXtN8lLzFl QBME9muezKN5nfzaEaKFQ+hUbM5KdlAFr1vqhXStOwxaKmDsLsFoofNesnM4FlxZhvu+Z9Zg/jp oq9klDNTGJmZd9xsxF0pXXvBRWc4w02bj0L5+slJMeDZUHirhSQMt69kEzlreIj3t0ChwRd7JSq 0GL62PtQfpFfNSZbU4y5a9fh5lfAvZ0DbmtQMV4nO5YNLvgZclMuevwr/OxCHSSeM7xGkDAZoOF IpNpk9B7+oip3DA= X-Google-Smtp-Source: AGHT+IF/Yu/Y0R4xH9f9dHoB83PSVbzCsGqc/QxGowF90fW6oVyHwIT4eE2aWQDQg1KvfZURrirWgUvpP/uABwCzLLM= X-Received: by 2002:a05:6102:54a1:b0:5db:1e80:7816 with SMTP id ada2fe7eead31-5db1e807cc4mr1528461137.24.1761162226620; Wed, 22 Oct 2025 12:43:46 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 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> In-Reply-To: Date: Wed, 22 Oct 2025 22:43:35 +0300 X-Gm-Features: AS18NWBs0KuI6kE6bxtm3bpRoqeVnaUI5PY-HcED9Yi3XOtHfT1ACb5vgEYtPdE Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 To: John Bafford Cc: Rob Landers , Aleksander Machniak , PHP Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) Hi > * Is TrueAsync intended strictly to enable concurrency without parallelis= m (e.g. single-threaded cooperative multitasking)? > Is there a future path in mind for parallelism (actual simultaneous execu= tion)? 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 If you=E2=80=99d like, I can elaborate on this idea, though probably not in= this thread. > Following on from that question, I note that there is no way to annotate= types as being safely sendable across concurrent execution contexts I actually studied this topic about a year ago. All of this can be done if one really wants to. To put it simply, implementing a SharedObject is already possible now, and it seems that it already exists in the parallel extension. As for data types and deep changes to PHP, that=E2=80=99s not directly rela= ted to TrueAsync. And even if it is, it can always be changed in the future. If someone decides to create a parallel version of PHP, they will definitely face backward compatibility issues. I wouldn=E2=80=99t even worr= y about that :) > That said: the TrueAsync proposal isn't proposing async/await keywords. There is an RFC proposing new syntax, but it was unanimously decided not to use it. For now. Maybe in PHP 9? > Perhaps it's sufficient to say that "TrueAsync" is single-thread only, an= d the multithreaded case will be handled with a completely different API la= ter so BC isn't an issue. But either way, this should > be at least mention= ed in the Future Scope section. Yes, of course, that=E2=80=99s possible. > * 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 inter= face to indicate that contract. It seems to me that this discussion has gotten a bit tangled: 1. Functions like awaitXX are not part of this RFC, yet we=E2=80=99re discussing them. Is that really necessary? 2. Awaitable objects do not return multiple values. 3. The Awaitable interface is basic for others, just like in many other programming languages. And for some reason, it=E2=80=99s not consider= ed a problem there. So far, no real example has been found where this would actually be a probl= em. > For example: Swift's standard library provides the AsyncSequence Comparing the Swift model directly with TrueAsync would be quite difficult, and such a discussion would require studying Swift=E2=80=99s implementation. It=E2=80=99s not even worth comparing it to Rust, since Rust has its own Future-based model, while Swift relies on code generation. I haven=E2=80=99t looked deeply into this topic, so I can=E2=80=99t really = add much more. It would be good to fully figure things out with PHP first :) > The answer in Swift to what happens if multiple readers await a non-idemp= otent Awaiter This is the general approach for the Event-Driven pattern, because asynchronous execution under the hood is event-driven. That=E2=80=99s exactly why the Awaitable exists. It acts as an EventProvide= r, and await() is effectively a subscription to events. Therefore, when await, awaitAll, or awaitAny is called, the code receives the first event, not multiple events. > I don't have a particular view on whether values should be replicated to = multiple readers or not, > but I do find it a bit annoying that Swift's standard library doesn't pro= vide an easy way to get replicated values. The current RFC does not prohibit this. It does not restrict how objects produce their results or how many subscribers they send them to. This behavior is part of the object=E2=80=99s own contract. > For cancellation, I'm confused on the resulting value. Thank you, that=E2=80=99s a great catch!!! I need to check this case. > 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 th= ink of it that way. > I think Async\protect() and forcibly cancelling coroutines beyond callin= g $coroutine->cancel() should be removed. 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. 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. > Yes, this means that a coroutine might never complete. > But this is no different than non-async code calling a function that has = an infinite loop and never returns. The cancellation (a cooperative cancellation model) mechanism does not exist to interrupt infinite loops. It is designed to provide a simple yet powerful way to cancel coroutines that are running normally. =E2=80=9CNormally=E2=80=9D means without an infinite loop. > Also bikeshedding, but I would suggest renaming Coroutine to Task. It could be named that way too. Although I don=E2=80=99t think there=E2=80= =99s much difference here. But Task is a shorter word. Thanks, Ed