Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126601 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 qa.php.net (Postfix) with ESMTPS id 8BB3A1A00BC for ; Thu, 6 Mar 2025 11:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741260540; bh=BP1Jng0scHF2jIHmxxLSzlQhH6Ad/c5YlMVd3Ba+NY4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YffpNa42+RUGgJbYELbT12yt9E6YiHp2bYpbNFO7P6mqy3U7JOYGoR7WPNEKEJiD3 bJV1PBRuf7jJSnxFmzUanDtRzEiJ5WcZZJetMDR14LU3ABzySqVHojNHZCTrv1c+nM jzPz92hfxJe3Kgd10cXlOxh6H8lsiu6hu0tpIqEFvh9kVin3spE7ruQwVdgef3bEb8 yhS1MyJVEWYPedCYMJLAeefYKHWoXa62Wk6aPQhiw6kmBgeonblfbNJqLOW+MUUYzs zqZBnD009qfd2hMiYjqajrY0UiqI5AQS4ATjzfj/NDyRXFtcaJnfNxAki+dhLbSPH8 r1og8C0tLzYDw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD81D180088 for ; Thu, 6 Mar 2025 11:28:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 ; Thu, 6 Mar 2025 11:28:59 +0000 (UTC) Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-6febbd3b75cso477537b3.0 for ; Thu, 06 Mar 2025 03:31:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741260694; x=1741865494; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mKAjtvLEoM9kgJW6Z+D6vgnKLPUgAM6kUKMjuZfVYus=; b=i4LD7wAuTeNaqK1w8frMdJSOKK9KB9CLn4STr3USruGqtFqYm+WAMGpiEwSCbwktwt qlep4U/da48Op9qmzWTICvhW4BmAj8a4ikiB6H3m1rM2xuFlpbfE4c5W1rYeavCZvO5o 6XP4rSNPEgLHrMwtL6kZ8YlRqs7swNYNWZAnhZs+0n/ODNVPY8mOScAVWtklEeR6Ae7k w5kVaUdINSDgcfpUnTUM1P03IzhRWS5IixGYxyiO1XifdqoPTCk9ZFzCoAPlgColMvda JUcC7Z8mlGvxWvqhWdkvFCjzimZEv41VS8auKAQ/6qNzPpN/2z39/NEyTgS4bVw7zhyC /7wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741260694; x=1741865494; h=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=mKAjtvLEoM9kgJW6Z+D6vgnKLPUgAM6kUKMjuZfVYus=; b=rFUr+2XSNuokOH8ZnXVEQPpAgfw8pJtk/MU04+iprrjjXDWGCjQICIhm15HvTQu+eD ZsDxlg4Wo5tsRTkWe3BpI+coa66xspRvvwSusqlH1OUqxvuBbT/CD0EoR3+LOqtv1ZCw d8+zVK3NaIqdhDoxfAWzFbXycAXHRFi+0ElKxyepqjMKj6c/h50zF+iEfxsEKvnTYVV8 fN4YeUzShMaGeR7Pc/HoxUELmH5wYOjnKUd6tS0jAfwlbDTDaq9xw6iid1GGyqHBFssW fB4JT9psJo4UIvYaE+SH4BUSjAt5HeLkC8tLA+3GCzw4ODI5kquYlMyXYH+nPgDNCynb JC6A== X-Gm-Message-State: AOJu0YxETHM6/L0fpKiGtforbTveBaqRDDZfxgsmgyRIGM+p23YKfzYF hwmszxZmznQv4pC7QI8tWCe/0duk0wpGd10x5reLToVpilJrjie2NAakQ7HQ0rKTFWx/vjikWBe KGain4+0MhAnlQ/OqYFBBpAYPNvfmU3gI7Pq0qw== X-Gm-Gg: ASbGncu14K6Yp2FqVwZL+Jy0+e5yIkyhGjWmnqi0GMKxp3ReGmRzPGk51+FyKUOEWjK smBirBciKedsRhDww/jgBCgpbjQ/CubMdnjmljVeefv8I0/zXv2dufUfIImDavzG/44CjiX51Mh 5syKLRhAmNr7KzYqO5u3uARCmZlg== X-Google-Smtp-Source: AGHT+IGJOcf9mzV5qQO4vuKHrsEDO/9j4tAyMU0CHEccNxNM9Y1Ic2be9V2NfvmZ8mYkFphrn+oxN9pneYNF9IDZjDg= X-Received: by 2002:a05:690c:9508:b0:6fb:1f78:d9ee with SMTP id 00721157ae682-6fda301050emr81695947b3.15.1741260694402; Thu, 06 Mar 2025 03:31:34 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <9964db8c-0ffe-43d5-8246-47fc76b07180@app.fastmail.com> <78a03dd0-fd4a-4f4a-ad8a-37e5704f06fc@app.fastmail.com> <23e162f6-54b0-4564-9d79-7b3bdc3d1ab5@rwec.co.uk> <36cee7e3-2ef8-4f96-a72e-e67a99e5f9bb@rwec.co.uk> In-Reply-To: <36cee7e3-2ef8-4f96-a72e-e67a99e5f9bb@rwec.co.uk> Date: Thu, 6 Mar 2025 13:31:22 +0200 X-Gm-Features: AQ5f1JqACTKepPCWQuPOvNe33Bwq_vef_iTcKOIMwWhtyTeA0kPwPi-jesMXYQE Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000026c263062faad9fd" From: edmond.ht@gmail.com (Edmond Dantes) --00000000000026c263062faad9fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > In a syntax-and-semantics approach, we only need to describe the things people actually need. There is no doubt that syntax provides the programmer with a clear tool for expressing intent. > In the same way, do we actually need to design what an "async context" looks like to the user? Its implementation is more about deciding which paradigms we want to support. If we want to support global services that require local state within a coroutine, then they need a context. If there are no global "impure" services (i.e., those maintaining state within a coroutine), then a context may not be necessary. The first paradigm is not applicable to pure multitasking=E2=80=94almost all programming languages (as far as I know) ha= ve abandoned it in favor of ownership/memory passing. However, in PHP, it is popular. For example, PHP has functions for working with HTTP. One of them writes the last received headers into a "global" variable, and another function allows retrieving them. This is where a context is needed. Or, for instance, when a request is made inside a coroutine, the service that handles socket interactions under the hood must: 1. Retrieve a socket from the connection pool. 2. Place the socket in the coroutine=E2=80=99s context for as long as it= is needed. However, this same scenario could be implemented more elegantly if PHP code explicitly used an object like "Connection" or "Transaction" and retrieved it from the pool. In that case, a context would not be needed. Thus, the only question is: do we need to maintain state between function/method calls within a coroutine? > Do we actually want the user to be able to have access to two (nested) async contexts at once, and choose which one to spawn a task into? If we discard the Go model, where the programmer decides what to do and which foot to shoot themselves in, and instead use parent-child coroutines, then such a function breaks this rule. This means it should not exist, as its presence increases system complexity. However, in the parent-child model, there is a case where a coroutine needs to be created in a different context. For example: - A request to reset a password arrives at the server. - The API creates a coroutine in a separate context from the request to send an email. - The API returns a 201 response. In this case, a special API is needed to accomplish this. The downside of any strict semantics is the presence of exceptional cases. However, such cases should be rare. If they are not, then the parent-child model is not suitable. To resolve this issue, we need to know the opinions of framework maintainers. They should say either: *Yes, this approach will reduce the amount of code*, or *No, it will increase the codebase*, or *We don't care, do as you like* :) --00000000000026c263062faad9fd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>=C2=A0 In a syntax-and-semantics approach, we only need to describe the things peo= ple actually need.

There is no doubt that syntax provide= s the programmer with a clear tool for expressing intent.

> In the same way, do we actually need to design what an "async co= ntext" looks like to the user?

Its implementa= tion is more about deciding which paradigms we want to support.
<= p>If we want to support global services that require local state within a c= oroutine, then they need a context. If there are no global "impure&quo= t; services (i.e., those maintaining state within a coroutine), then a cont= ext may not be necessary. The first paradigm is not applicable to pure mult= itasking=E2=80=94almost all programming languages (as far as I know) have a= bandoned it in favor of ownership/memory passing. However, in PHP, it is po= pular.

For example, PHP has functions for working with HTTP. One of t= hem writes the last received headers into a "global" variable, an= d another function allows retrieving them. This is where a context is neede= d. Or, for instance, when a request is made inside a coroutine, the service= that handles socket interactions under the hood must:

  1. Retrieve = a socket from the connection pool.
  2. Place the socket in the coroutin= e=E2=80=99s context for as long as it is needed.

However, this = same scenario could be implemented more elegantly if PHP code explicitly us= ed an object like "Connection" or "Transaction" and ret= rieved it from the pool. In that case, a context would not be needed.

Thus, the only question is: do we need to maintain state between function/= method calls within a coroutine?

> Do we actually want the user to= be able to have access to two (nested) async contexts at once, and choose = which one to spawn a task into?

If we discard the Go model, where the= programmer decides what to do and which foot to shoot themselves in, and i= nstead use parent-child coroutines, then such a function breaks this rule. = This means it should not exist, as its presence increases system complexity= . However, in the parent-child model, there is a case where a coroutine nee= ds to be created in a different context.

For example:

  • A re= quest to reset a password arrives at the server.
  • The API creates a = coroutine in a separate context from the request to send an email.
  • = The API returns a 201 response.

In this case, a special API is = needed to accomplish this. The downside of any strict semantics is the pres= ence of exceptional cases. However, such cases should be rare. If they are = not, then the parent-child model is not suitable.

To resolve this iss= ue, we need to know the opinions of framework maintainers. They should say = either: Yes, this approach will reduce the amount of code, or = No, it will increase the codebase, or We don't care, do as you= like :)=C2=A0=C2=A0

--00000000000026c263062faad9fd--