Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129385 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 AFE721A00BC for ; Sat, 22 Nov 2025 09:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763802796; bh=7Hcw7eiwqMwe4c4lkV1Uvt4MYFGex9IiFTIyTqSiZIQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dHBXRiQRt3KTh3AQlSgBu+1aJ3usO/kGEIJ/7qNOv/m3jgo2ELS/4sZs2YG1yOW2B q2xHR3LrXHQ9MZb2G5lWqx47GkG5ttPVJ35nFlYGjEjY77U4okyUWolmohFM6DMkAg vd7s6Z4oCIMiArvHoDvTJZj4YUPpmyAiCkFr94TPbCPQaDwEnkyzh1cTHfyQrZZTcp vzp8zudILRx8abjOzfY1vo6W13u+Pf2lTq2hNQj4bz1SLN6mvAQ2jombGBMKvcIpCG vmVwDE8B9nppaygDcqJgo+zE9O3V+1EPMCitf4PpnLLGLrynh579wwfKYOvMF6qX/5 jigf7NrNHk4pA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4BB00180083 for ; Sat, 22 Nov 2025 09:13:15 +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=1.8 required=5.0 tests=BAYES_50,DMARC_NONE, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (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, 22 Nov 2025 09:13:15 +0000 (UTC) Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-3e3dac349easo1964530fac.2 for ; Sat, 22 Nov 2025 01:13:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763802789; x=1764407589; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=p42GBYxts34KpxdwmpvV83cBJMnKllQj1nyy86tucpI=; b=vUEIqUTc231l9O3FvpO9NNwdNrpS8G1TgPIfMolK0ZWLUOPXYL9vx9EnwvituU6m/j epbgXsSpTbwx9AT/cfIVJf3vBpJUJ6tIGBxm8J/Aq+pwDenZJwLRgt8KgAfraKxGZtHD baB+CVVXcijvygEhMJseo4zibVLrdZK6JyOuvB7TxC6lj5gJ+57//vXzCn9wz15hwQ8Q 5VAXqqikWC+NYd160G1jlPLwyI3mSMu5gPuLLK3klyslWqYdjoXLh6hMG7b5LuF60r0W C83F+6Do/Cx9JzSueO2W4VYVAJwM85fpsECHu5hExSk6VaNgFdkwwRMSsqXpPCIUK+8C nD0g== X-Forwarded-Encrypted: i=1; AJvYcCVdoXrCKHYN/+5QAMm++m+KnE6avUHGeIbQCgOr+QGXn+cIWhvIdqQwOxowqQPH/9LKH5DtJ5XMSeY=@lists.php.net X-Gm-Message-State: AOJu0YxMdLdq6VbS2rdB20nGLhJHd5XvEbIeEgnclJWtbUsmwL4SMgNq V803Wj++XUMifNj+5OYY2KcrCrT6DY4jFTEKhyPWa0PnkKElEZFYhx0bQ9q0OHQHoKQfVWgTBAL QvyuWBtHKzURuiuPmxrdz55TQFKJOJHk= X-Gm-Gg: ASbGncvMJ79pRqFbUlzcjHgFj4jDjCkRqv0zdlb77jdQ39v+FIMwB3GSd6TNUFU1HCU sRL3weCcZhAfd2RVyf6CE1mkIoOOsryjMGcpDd9y21cb357BmdvLU2P5Q/dv6Lm3SrbIut55GpK Nw7ajqk+rzz3uUXtoHNVzQcK9336LnaD/jSn3W/WgSp7t1j9oVqjH5CVbsLuzIGgXpmK+dLNazr T003g8lTEFpviBw4OLxr/gaYmPK7GnqPEiT5lXo9EQ89ccu2/aYUThs/k2o0Jz4kc++92YZGGhm pNoQJof/fxtsr3ii6IV2p4Q6S4y+bg== X-Google-Smtp-Source: AGHT+IFTCYm3f2wOJZZ7qV1FVhmzqopuaeiaIqOWQIRCYJj8KIkaAXCLZUdvkFS7WJtbNbzNsAN96hyGn1v+oWGmjuI= X-Received: by 2002:a05:6808:17a4:b0:450:ac94:5ef5 with SMTP id 5614622812f47-45115995a05mr2049545b6e.16.1763802789415; Sat, 22 Nov 2025 01:13:09 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 22 Nov 2025 10:12:57 +0100 X-Gm-Features: AWmQ_blIi8g8jukkC86yM--waLXuPZL6hbVcoyLO6JcUbNQi2nE8mMvrPQ4FpNk Message-ID: Subject: Re: [PHP-DEV] [VOTE] True Async RFC 1.6 To: Bob Weinand Cc: Edmond Dantes , "Rowan Tommins [IMSoP]" , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000b78d7306442b562a" From: bukka@php.net (Jakub Zelenka) --000000000000b78d7306442b562a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Bob, On Sat, Nov 22, 2025 at 5:50=E2=80=AFAM Bob Weinand w= rote: > Hey Jakub, > On 21.11.2025 12:29:16, Jakub Zelenka wrote: > > Hi, > > I think you seriously underestimate impact of this in the current PHP cod= e > bases where many applications depend on global state. Especially the lega= cy > ones but even the most popular ones. Just look into WordPress which use > global state extensively. Now imagine that some popular plugin decides to > use async which change some of its globals (like $post or $wp_query) duri= ng > the suspension of the main code. I would assume this could horribly break > things. Don't forget that other code don't have control over the plugin a= nd > it might not even know that async is used there. So I'm not sure if this > design is compatible with WordPress and similar applications where global > state is used extensively. If that's the case, it's of course a problem > because those applications (well WordPress on its own in fact) compose th= e > majority of PHP users so introducing something that would have potential = to > break its code would limit usability of the whole feature and could even > lead to loosing more users that we could gain from introducing this featu= re. > > So I think it will need to find some solution that will prevent this from > happening. I guess there might be few options > > 1. Disallow suspension of the main sync code which is effectively some > sort of colouring. > 2. Preventing access to globals from coroutine which I'm not sure is even > fully doable from the engine PoV - it would mean some sort of different > execution mode that could not use globals (e.g. global keyword and callin= g > some functions that change global state). It would need channels for > communications between coroutines. The advantage of such model would be > possibility to combine it with threads in the future but I could imagine = it > could still lead to some subtle issue for years as there is internal glob= al > state as well that can lead to some surprises. But maybe that would be > worth it. > > I think you seriously misunderstand this. > > Async does not allow you to introduce some effects from the outside. You > have to actively opt-in to running stuff in parallel. > But you don't have to opt in into it in this current form. If some external plugin calls spawn (without await), then it can suspend other plugins (that didn't opt in to it) in places where it wasn't expected. > The problematic part, is, when you call code inside of coroutines, which > is not safe to be run in parallel with other code. > > I.e. if you start writing code like `await([new Coroutine(fn() =3D> > not_safe_to_run_twice()), new Coroutine(fn() =3D> not_safe_to_run_twice()= )])` > (pseudo code). Where not_safe_to_run_twice() shares some context. > > Well if you call await, you should be safe but that's not requirement here. You can just spawn coroutine and main functions continues the flow to other plugins that didn't opt in to async. So, when you write async code, you have to *know* that the called code is > allowed to run in parallel with any other code which you explicitly chose > to run in parallel with it. E.g. if you'd run two wordpress functions whi= ch > don't have side-effects (not even to internal state), then you're perfect= ly > fine doing that. If you run wordpress functions in parallel which may jum= p > back to the scheduler during its operation and leave the internal state i= n > some intermittently invalid form, then yes, then you have a problem. > I'm not saying that is not possible to write safe code. This would be perfectly possible and recommended, of course. The problem is that it doesn't prohibit writing unsafe code in any way. > But if your goal is to just do a localized parallelized operation which > you know is safe to run in parallel - e.g. some image processing and > storing some stuff in the database, within your wordpress plugin, that's > absolutely fine. It won't break anything. > Not sure if you worked with WordPress but if you want to query something, it is often done through $wp_query global so it might actually not be always safe if there is some IO done in between building the query. > Essentially: Just don't call stuff in parallel which you don't know is > safe to be called in parallel and you're golden. > That's, of course, correct advise but I'm not sure you realise that if those rules are not somehow enforced, it will be most likely get ignored and lead to problems that many people are worried about. Also it might not be immediately obvious that something is safe because the change of state might happen indirectly and be deeply nested. Kind regards, Jakub --000000000000b78d7306442b562a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Bob,

On Sat, Nov 22, 2025 at = 5:50=E2=80=AFAM Bob Weinand <bobw= ei9@hotmail.com> wrote:
=20

Hey Jakub,

On 21.11.2025 12:29:16, Jakub Zelenka wrote:
=20
Hi,

I think you seriously underestimate impact of this in the current PHP code bases where many applications depend on global state. Especially the legacy ones but even the most popular ones. Just look into WordPress which use global state extensively. Now imagine that some popular plugin decides to use async which change some of its globals (like $post or $wp_query)=C2=A0during the suspension of the main code= . I would assume this could horribly break things. Don't forget that other code don't have control over the plugin and it might not even know that async is used there. So I'm not sure if this design is compatible with WordPress and similar applications where global state is used extensively. If that's the case, it's of course a problem because th= ose applications (well WordPress on its own in fact) compose the majority of PHP users so introducing something that would have potential to break its code would limit usability of the whole feature and could even lead to loosing more users that we could gain from introducing this feature.

So I think it will need to find some solution that will prevent this from happening. I guess there might be few options

1. Disallow suspension of the main sync code which is effectively some sort of colouring.
2. Preventing access to globals from coroutine which I'm not sure is even fully doable from the engine PoV - it would mean some sort of different execution mode that could not use globals (e.g. global keyword and calling some functions that change global state). It would need channels for communications between coroutines. The advantage of such model would be possibility to combine it with threads in the future but I could imagine it could still lead to some subtle issue for years as there is internal global state as well that can lead to some surprises. But maybe that would be worth it.

I think you seriously misunderstand this.

Async does not allow you to introduce some effects from the outside. You have to actively opt-in to running stuff in parallel.=C2= =A0

But you don't have to opt in into it in = this current form. If some external plugin calls spawn (without await), the= n it can suspend other plugins (that didn't opt in to it) in places whe= re it wasn't expected.
=C2=A0

The problematic part, is, when you call cod= e inside of coroutines, which is not safe to be run in parallel with other code.

I.e. if you start writing code like `await([new Coroutine(fn() =3D> not_safe_to_run_twice()),=C2=A0new Coroutine(fn() =3D>=C2= =A0not_safe_to_run_twice())])` (pseudo code). Where=C2=A0not_safe_to_run_twice() shares some context= .

Well if you call await, you should be sa= fe but that's not requirement here. You can just spawn coroutine and ma= in functions continues the flow to other plugins that didn't opt in to = async.

But if your goal is to just do a localized parallelized operation which you know is safe to run in parallel - e.g. some image processing and storing some stuff in the database, within your wordpress plugin, that's absolutely fine. It won't break anyt= hing.

=C2=A0Not sure if you worked with WordPres= s but if you want to query something, it is often done through $wp_query gl= obal so it might actually not be always safe if there is some IO done in be= tween building the query.

Essentially: Just don't call stuff in parallel which you don'= ;t know is safe to be called in parallel and you're golden.

That's, of course, correct advise but I'm not su= re you realise that if those rules are not somehow enforced, it will be mos= t likely get ignored and lead to problems that many people are worried abou= t. Also it might not be immediately obvious that something is safe because = the change of state might happen indirectly and be deeply nested.

Kind regards,

Jakub
--000000000000b78d7306442b562a--