Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128909 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 0BFD61A00BC for ; Wed, 22 Oct 2025 17:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761154866; bh=8Y+Yv8b0SwIzRmzD7KYg/N5vUJJ2kzBE6yGwVvSsJsw=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=Zv09glsCwRtkgf/iSPwkiJLs+LqW0Npngw8Y/VdrKH7Ufw95gRELeKt4tRD1rO5X7 fBn5Exc50klPGv4ot6bIcmsa4tWYiG0wv9wRRgeR4cE5MUrptA9T++ACa5Dsjb5Igi jHSpgm9MFPG8LYfbwdT9MelXGhyQ6n0/vT/totRraBhinnNxaFtgVKitFwyfOlzOAC Nu4aKD0759mIydEjelLRStcnwHY/XquSg+RzJ/D5VKJnTqZAq/tOfQB9Q16L3eSZYp hSh38VPQySEd3Z+zs5nES/XcgunczGtI2YiDFXJxxASPxGKYuqm29/BTxpF4i2VzX+ nAVWXYF5/42/Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AA55E1801DF for ; Wed, 22 Oct 2025 17:41:05 +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 fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 22 Oct 2025 17:41:05 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id ED604140011F; Wed, 22 Oct 2025 13:40:59 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Wed, 22 Oct 2025 13:40:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm3; t=1761154859; x= 1761241259; bh=8Y+Yv8b0SwIzRmzD7KYg/N5vUJJ2kzBE6yGwVvSsJsw=; b=t wkwxPfyfwFcttZLlgFgzpjsSNpd6CvDl70eGp7x1u2G5h2/aqEDKsf419X+MrLAj s/AiLXNW+MLEfxHd9Ho806ZgTvyoKXfx/F7tJZ3IfRej+m0Eld+k9Wjvwi2JgRiV 1ESb0vUApYFBQet5XK4W6WGo4qzF1JBioymvQrwiw0w/o2gv0hNYM6zNEdHmd2El /piy6d6mOYXvm8ufLqE8JN4fEkML6LNKSUtQXaCbleG4iRtu6AiPEo3ZV9ngtkVd 0H0nKUVkrIAlcearGAGc//uJygQmaGyO9xBIBGU35qgi+rjdnnAEljcS4ANOR8dn rdufHf5R4Ty9jeWUB75zA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; t= 1761154859; x=1761241259; bh=8Y+Yv8b0SwIzRmzD7KYg/N5vUJJ2kzBE6yG wVvSsJsw=; b=jvyqAj6mfY1BSlMkrQHupXvu/1IlLp1l4awjlwFban1V+2flHqz 9bfmPdb0w9JRqZljy5z8pbRSSGvlvUUYVvxZwc8Axi9vOgKSVPQ5R/jbZ3YwmiOl u/UKa9amO8ULftdGbvt0wnbwJSHMfXzAmHIgGkrWJkcwioHTEN6Nk6JHV2PNtawu ll43EB7Qk8EeqbWvbnzPEqzVU3PIGuzGuGZX81BsGQ+eHXAVY5Q8g9TrPmGwQ7fm W0ulht7j1LU75e0vdyvtUqfPGVu7aYr2/5M9CBNDrsaSBarcmhw2YnaHH3ZdIQDf L6+7WN/qRFVvHQwQhV4goZYJV4im5VRyGTg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddugeegvdduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfn rghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtth gvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfhfeekjefflefgvedvkeduteejjedt tdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehroh gssegsohhtthhlvggurdgtohguvghspdhnsggprhgtphhtthhopeegpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopegrlhgvtgesrghlvggtrdhplhdprhgtphhtthhopegvug hmohhnugdrhhhtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlshes lhhishhtshdrphhhphdrnhgvthdprhgtphhtthhopehjsggrfhhfohhrugesiihorhhtrd hnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 2D7C5182007A; Wed, 22 Oct 2025 13:40:59 -0400 (EDT) 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: AG5VjklPAjNR Date: Wed, 22 Oct 2025 19:40:01 +0200 To: "John Bafford" , "Edmond Dantes" Cc: "Aleksander Machniak" , "PHP Internals" Message-ID: <9ec19485-61cc-460b-adeb-1b2262a68578@app.fastmail.com> In-Reply-To: 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> Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 Content-Type: multipart/alternative; boundary=7a8815f477054b949901fad6ea66db47 From: rob@bottled.codes ("Rob Landers") --7a8815f477054b949901fad6ea66db47 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Oct 22, 2025, at 19:24, John Bafford wrote: > Hi Edmond, >=20 > > On Oct 22, 2025, at 09:09, Edmond Dantes wrote: >=20 > Thanks for putting in the work to start to bring async support to PHP.= I have a few initial comments: >=20 >=20 > * Is TrueAsync intended strictly to enable concurrency without paralle= lism (e.g. single-threaded cooperative multitasking)? Is there a future = path in mind for parallelism (actual simultaneous execution)? >=20 >=20 >=20 > * Following on from that question, I note that there is no way to anno= tate types as being safely sendable across concurrent execution contexts= . PHP does have a thread-safe ZTS mode. And a long-term goal should be t= o allow for parallel (multiple concurrent execution) asynchronous tasks,= especially if we want to expand asynchronous from just being a way to a= ccomplish other single-threaded work while waiting on I/O. >=20 > In a concurrent environment, one has to consider the effects of multip= le threads trying to read or write from the same value at once. (Strictl= y speaking, even in a single-threaded world, that's not necessarily safe= to ignore; the stdclib or kernel code behind the scenes may be doing al= l sorts of shenanigans with I/O behind everyone's back, though I suspect= an async-aware PHP could itself be a sufficient buffer between that and= userspace code.) >=20 > With multithreaded code, it's generally not safe to pass around types = unless you can reason about whether it's actually safe to do so. This co= uld be trivially encoded in the type system with, say, a marker interfac= e that declares that a type is safe to send across threads. But this nee= ds to be opt-in, and the compiler needs to enforce it, or else you lose = all pretense of safety. >=20 > It's tempting to handwave this now, but adding it in later might prove= intractable due to the implied BC break. E.g. trivially, any call to sp= awn() might have its task scheduled on a different thread, but you can't= do that safely unless you know all types involved are thread-safe. And = while you could determine that at runtime, that's far more expensive and= error-prone than making the compiler do it. >=20 > That said: the TrueAsync proposal isn't proposing async/await keywords= . Perhaps it's sufficient to say that "TrueAsync" is single-thread only,= and the multithreaded case will be handled with a completely different = API later so BC isn't an issue. But either way, this should be at least = mentioned in the Future Scope section. Off-topic a bit: but for the last several+ weeks, I=E2=80=99ve been rewo= rking TSRM (moving it into Zend & making it a bit more frankenphp friend= ly) which could -- eventually -- allow for passing arbitrary types betwe= en threads without complex serialization and shenanigans. =E2=80=94 Rob --7a8815f477054b949901fad6ea66db47 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Wed, Oct 22, 2025, at 19:24, John Bafford wrote:
Hi Edmond,
<= div>
> On Oct 22, 2025, at 09:09, Edmond Dantes <edmond.ht@gmail.com> wrote:

Thanks for putting in the work to start to bring= async support to PHP. I have a few initial comments:


* Is TrueAsync intended strictly to enable concurr= ency without parallelism (e.g. single-threaded cooperative multitasking)= ? Is there a future path in mind for parallelism (actual simultaneous ex= ecution)?



* Follo= wing on from that question, I note that there is no way to annotate type= s as being safely sendable across concurrent execution contexts. PHP doe= s have a thread-safe ZTS mode. And a long-term goal should be to allow f= or parallel (multiple concurrent execution) asynchronous tasks, especial= ly if we want to expand asynchronous from just being a way to accomplish= other single-threaded work while waiting on I/O.

In a concurrent environment, one has to consider the effects of multi= ple threads trying to read or write from the same value at once. (Strict= ly speaking, even in a single-threaded world, that's not necessarily saf= e to ignore; the stdclib or kernel code behind the scenes may be doing a= ll sorts of shenanigans with I/O behind everyone's back, though I suspec= t an async-aware PHP could itself be a sufficient buffer between that an= d userspace code.)

With multithreaded code, it'= s generally not safe to pass around types unless you can reason about wh= ether it's actually safe to do so. This could be trivially encoded in th= e type system with, say, a marker interface that declares that a type is= safe to send across threads. But this needs to be opt-in, and the compi= ler needs to enforce it, or else you lose all pretense of safety.
<= div>
It's tempting to handwave this now, but adding it in = later might prove intractable due to the implied BC break. E.g. triviall= y, any call to spawn() might have its task scheduled on a different thre= ad, but you can't do that safely unless you know all types involved are = thread-safe. And while you could determine that at runtime, that's far m= ore expensive and error-prone than making the compiler do it.
=
That said: the TrueAsync proposal isn't proposing async/a= wait keywords. Perhaps it's sufficient to say that "TrueAsync" is single= -thread only, and the multithreaded case will be handled with a complete= ly different API later so BC isn't an issue. But either way, this should= be at least mentioned in the Future Scope section.

Off-topic a bit: but for the last several+ weeks, I=E2= =80=99ve been reworking TSRM (moving it into Zend & making it a bit = more frankenphp friendly) which could -- eventually -- allow for passing= arbitrary types between threads without complex serialization and shena= nigans.

=E2=80=94 Rob --7a8815f477054b949901fad6ea66db47--