Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126862 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 3A3101A00BC for ; Thu, 20 Mar 2025 14:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742482477; bh=Tw+yXDONTyilhrcTJId652IssyUJAkZbiynv1DbSZAg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=O/DYQBomP/l93iSWyA08clNOyhktQMSEva8Nhz3Ob2dNdnORGIartRES+g6XnyUys K2RHRv0851IS6fEDOMLEyprcz8kJ68ao7h2drTGhxLnTY2mtIOCcUqvWZanEb+IraN HyMDA8HR8t6xmZyz2IghNqYoEG3LQNPjAmZC0UY5b+BYPoHEDegowW+g6koPbWYkwr 1nUhpw06rl4ULf0pr92HoZErii2nsfJUnfzDkE8yPVqSVmcJUJHGmdLRJmAflHIo1j 3gWwS8UyRNo1jpn3RYvIBXOg7xD8Uk1y/o8pSe0ZNbXDp9Dh7q30QsICVbAHzgNr51 0NjyhnwQQn/Tw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9ECD31806D5 for ; Thu, 20 Mar 2025 14:54:36 +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=-1.2 required=5.0 tests=BAYES_50,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-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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, 20 Mar 2025 14:54:36 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e5dc299dee9so862882276.3 for ; Thu, 20 Mar 2025 07:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742482626; x=1743087426; 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=9fP1GF86w1h2I3tv6jBh5AlIRjU/p4drr/TMQB4yK4g=; b=moCo0rx1Faxr4P1IVKzHP/sgwW9ECqfp3bP+g1ImWov9iYH10e0exU0qixKb55GnK3 KDevtAMSclYO433HyNE/rHH4wfNdcbs6IQNEfd7hS8dhLiaKQdRF78m1EkBVVF9q2kNn pvx1i3DEIs6FhOWPr7sYTgAHK9SqAJniamWMf5dYBCNB3KFhvZgydHIaqRPad1G02pPQ Bo8+4nL4APCREUpJ0sLne26O5nbzpP6NMqJvzN9CEcRxsHE8M4Ujw/lfwx27C0WU95SS sDB99yNSaOQn2A6tDe+mB3LIsACE9WybfdsYoVvjWfJXLnCmhkeWF8P60lj7bkpKS9eW aYyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742482626; x=1743087426; 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=9fP1GF86w1h2I3tv6jBh5AlIRjU/p4drr/TMQB4yK4g=; b=lCI4oVpbLpsDgeQ7R0pM5ZfhrY7E5tWTmEz52JT5ZSIiWmeji0t7MSLvF1hxcxDuU3 EyhFdPYzT4xk2DpFCj3+HaYYNF8r4t/L5jq/hvWKmumQj0MADyC75+5V3vvXCqf0cu82 OVsb0CHJlh8hTERZrlji1DGcsZrkG4aGp6bajWBQ8Q7XKuvrNJx/HU4kMqo9USfGtraa ybwIfWEGzXwKEuADGJ/BIfWZ57xVrZjCD/+dNHym7SpyaCcWmPIsqrXtO2Ut710/Banb abhlFzmXpW3JOYjLLh6gy1CUZJF+Az5J57XkdCAWhjlpKF2Yp2uKYfjV965Fs1daGjkq xznQ== X-Forwarded-Encrypted: i=1; AJvYcCWUWNwVFl2HGI+9u8oCuBtgUVDpaClP2TcnKDJWN3h1Aex766Bbt1rf5nwNtzAV+F4MI9puNm+cV4c=@lists.php.net X-Gm-Message-State: AOJu0YydmPujs5dAsCfMVAfrTf+13BiGzenot0TwYtSIj1wa1ak6SO7l aTfyWJ6TrCpmAfy63/LMJ/oOeg8/3MTKQ96iHNL64TqUzdh/j0cBfY7qIu4cSjLr76FUz8ixGkq ym37YnDKMV4ILA9XEl72XTr4rT7i068Fp5lcrrw== X-Gm-Gg: ASbGncuI+LfWubSeBv4V+z9yq0uD3/0aXdxXscrhK8QUN3oR4Da7CALtRAP1hnD89vG 9hCcMjj+rjK3KUnL531PMPZ8jDjNy6DfS4QVl2d4w8nKOXmeF1A7WO1WtWaAHcbvozDxzQSzj4O BrhZYKfEKEqJTvQSXDgQ7i2USULQ== X-Google-Smtp-Source: AGHT+IHueujzDEv3XCz5CEe34U75rDwOiUbmS7QIAW7ftNZRVpXM2joDp918pe5xWEFUPcPAlE/Z+aysV1LhwN4udaE= X-Received: by 2002:a05:6902:100d:b0:e63:d10e:edc1 with SMTP id 3f1490d57ef6-e667b3a9761mr8526620276.3.1742482626255; Thu, 20 Mar 2025 07:57:06 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <72bd5401-53a9-409f-ad45-687333401961@rwec.co.uk> <6987D912-CE46-4145-A8CE-732CA590A522@rwec.co.uk> <2F013672-9937-4AB1-BC46-86F3D342BE6B@rwec.co.uk> <743c84d4-28db-4f68-80e5-3cad2dac6e68@rwec.co.uk> <8d69c4d4-d393-4085-b60a-1063155ee8a3@app.fastmail.com> In-Reply-To: <8d69c4d4-d393-4085-b60a-1063155ee8a3@app.fastmail.com> Date: Thu, 20 Mar 2025 16:56:55 +0200 X-Gm-Features: AQ5f1JqOHegMhzAHm_lhJl1GFy-ouaQChzGDZlqfBNxtrr9IMxYJPeEZzWMuV0I Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: Rob Landers Cc: "Rowan Tommins [IMSoP]" , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000f721980630c759dc" From: edmond.ht@gmail.com (Edmond Dantes) --000000000000f721980630c759dc Content-Type: text/plain; charset="UTF-8" > > This example highlights one of the concerns I have with fibers and this approach in general. That example will still execute synchronously, taking file_get_contents() * 3, even though it is in a coroutine function. > Is that really a problem? If a programmer wrote the code `$x = 1 / 0`, then the issue is definitely not with the division operation. > If you wanted to make it asynchronous, you'd have to do something like so: Because this is more of an anti-example :) You shouldn't write code like this. But if you really want to, at least do it like this: ```php $x = await spawn fn => [spawn file_get_contents($a), spawn file_get_contents($b), spawn file_get_contents($c)]; ``` But this is also an anti-example because what's the point of writing the same code three times when you can use a concurrent iterator? ```php $x = await Async\map([$a, $b, $c], "file_get_contents"); ``` (The functions will be included in another RFC) --000000000000f721980630c759dc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>
>=C2=A0 This example highlights one of the concerns I have with fibers and this app= roach in general. That example will still execute synchronously, taking fil= e_get_contents() * 3, even though it is in a coroutine function.
>

Is that really a problem? If= a programmer wrote the code `$x =3D 1 / 0`, then the issue is definitely n= ot with the division operation.

> If you wanted to make it asynchronous, you'd have to do = something like so:

Because= this is more of an anti-example :) You shouldn't write code like this.= But if you really want to, at least do it like this:

```php
$x =3D await spawn fn =3D> [spawn f= ile_get_contents($a), spawn file_get_contents($b), spawn file_get_contents(= $c)];
```

But this is also an anti-examp= le because what's the point of writing the same code three times when y= ou can use a concurrent iterator?

```php
=
$x =3D await Async\map([$a, $b, $c], "file_get_contents");
```

(The functions will be included in an= other RFC)=C2=A0=C2=A0
--000000000000f721980630c759dc--