Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129401 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 37BE11A00BC for ; Sat, 22 Nov 2025 15:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763827188; bh=lLvrr+kurxiEJvApnpxMc9/573kb42I0JwdNqRQRTcg=; h=References:In-Reply-To:From:Date:Subject:Cc:From; b=Ir9hjPafaKo3DBW0al8L87GbQJVFvdS/E2kp2bWf9Ugb2vQL9BsUPuvaSrwS71yDH uaxxOKbqc9NWw/RF5tCOhDEF0kTU/4bRIqsSFlga7l7wvPRcKOZHo2yWzw87M5Qfl5 2ItpeKEXbPqh7xjCeExZaLw25jD6Rqou2yaOBT+0MHRroEzvJF9CL3XIlA/HhvVeRl E9Fu5GKeqFbEgyVmZpbJTaxmCCWyZVFCGPDD51Zc/DSNh40iCbXYr1E8AJHsiX7JZA 0hqoB9Gkw6VQe4OqCERcishWGZ2pwgc0mZfv/rNxErfmvnKXzSda3kO6JBcnsYNQ1Z L4gs531MR4e7g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C2CF6180077 for ; Sat, 22 Nov 2025 15:59:44 +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=4.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, MALFORMED_FREEMAIL,MISSING_HEADERS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) (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 15:59:44 +0000 (UTC) Received: by mail-ua1-f42.google.com with SMTP id a1e0cc1a2514c-93728bac144so1690530241.2 for ; Sat, 22 Nov 2025 07:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763827178; x=1764431978; darn=lists.php.net; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=CP2ubosRmujB39xlJYUONTJ1LSTzUPEFkHU4tEu3mhw=; b=f92M2WLryzJmiB3w3SXQaQg1WxgNq9eOyDuSz6eJyt5HR2prqRoAzJtJmAqUPd7rP+ 2B9cq/8nwtMSpwwuY4PDjMDwXjMvUANubpyLPqHYXz+abVRUPvsvHi9SlkDCiYeNP8Ix rQqhC3rO+9bIZoNciu+MSF5KHhF5Zhr74y4O1e0QqH+rYfUa0nL5dNV92XDaEKTby/C/ DJzh/7M95KR8BNMHn+JXZ2uDjb3Tjbh8CPYNJ/VXXtD53sKFY+BDs54pAR0ElDfA7iFr idyA7UGYVKBahBADy3DHoyTgDxsE7OF5Zct0PdvT2ZTz2JWtmPmZAhToL7VN3YC/JlFW zp6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763827179; x=1764431979; h=cc: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=CP2ubosRmujB39xlJYUONTJ1LSTzUPEFkHU4tEu3mhw=; b=eZ/eq5vpgWD5v0Hv/u0cxHqhlgnxIiVXfoiEc5s2BYZNDKIkw9naXtObYLwLFr/lz9 6eKGdykTOWDjKkwgGTvMigG2w5Fqw1bpDfxbf5r6l5oH7pqlqSuI9uUmel0YrGIC/h7D y7Y42DnC28IZ/CM70OxUUBdg6t1mItRxULbkPxtmqkh4YwsnZklC/C3lZ/9VJU1MxouC isk6UDSO8ebLRox4T6B/hIcoYwPQfkbxcdmzcUooa9FbMR9exGjqoiXeh4NiAVOYOYri K4DWjH2m5YFdLPDOhqEpTyjqwX//D2IKcgPrS9uqXRBa5zn/eACSYfNnPF2aMbUty2Hi teKg== X-Gm-Message-State: AOJu0Yx5rzK8usprdA0jdvCZyaIum8KmwXj5q6qUoiIIl+GWILQlHlbw xTSBdyPM9U5b/oPUYryqjtyTfFylSJXo6QoC8ZpulL8hT3EBxYt+DraqOCszBiEmBOeuD2hxD5/ 4IwR4yPcmS3HKXJQ+cICDHeGoP2tRzS9onBZ1 X-Gm-Gg: ASbGncu3f3kdp7sjWKNF30lVFC3DBDF8cVKYot+bZ7zKL+70dN5RNUAHN6zhMIwyHf2 TQtR8u10rQKWgChtSIwgMA0QMmiehyS744jFI/Md95nVDCHHRDmblY4iABpAo+2g1JjdsKALnya GHzSIMjkT0Yukz+JsSB5yadm1PtCzD0odA/hfCXQx1Ys8GNqg4ca/Wcyh+IsVOiXhZxf6PRaczJ 9QzNl5OZKx40aKYyOB9T9AmC6aZvGFCdKfScVZ3/q+cm8j4QDPvexDTVGJawRg7mJoSJM1SW+Er WtwMVmF2uz9n/WfpU8nb6CcmE4mu X-Google-Smtp-Source: AGHT+IER4aYxe3laHi8kNTbhWDhi7jZTynt1bNmOxDhjgo3lBrH1ka9McWTuwhZubWC9yQOqBniG/vAWd28OZkmo0A0= X-Received: by 2002:a05:6102:2908:b0:5df:aa69:beab with SMTP id ada2fe7eead31-5e1de419226mr2315006137.29.1763827178677; Sat, 22 Nov 2025 07:59:38 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <383528143.397454.1763760932585@email.ionos.de> <691963327.399484.1763796022993@email.ionos.de> <1402906904.784903.1763811759896@email.ionos.de> <2015208655.784984.1763811978476@email.ionos.de> <980296152.1071.1763813573083@email.ionos.de> <92865666.4510.1763818506332@email.ionos.de> <329450798.8037.1763822426377@email.ionos.de> In-Reply-To: Date: Sat, 22 Nov 2025 17:59:26 +0200 X-Gm-Features: AWmQ_bnLbOywjtcDP-lkcmpTsWMfMy3qYVhBnT1d2Sf1Yk3mrsSWovuavKL4Ke8 Message-ID: Subject: Re: [PHP-DEV] [VOTE] True Async RFC 1.6 Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: edmond.ht@gmail.com (Edmond Dantes) ```php use Async\spawn; use Async\Channel; function worker(Channel $tasks) { // Start a process for this coroutine $proc = proc_open("php worker.php", [ ["pipe","r"], ["pipe","w"], ["pipe","w"] ], $pipes); $stdin = $pipes[0]; $stdout = $pipes[1]; while (true) { // Receive a task (this suspends the coroutine) $task = $tasks->recv(); // Write task to process (suspends while writing) fwrite($stdin, $task . "\n"); // Read result (suspends while waiting for data) $result = fgets($stdout); ... make some else } } $tasks = new Channel(); // Start N workers for ($i = 0; $i < 10; $i++) { spawn(worker(...), $tasks); } // Producer... $tasks->push(...); $tasks->push(...); $tasks->push(...); // Close Channel auto after leave function ``` Please look at this code. There are three or five other ways to implement it. And most of them would likely be worse in terms of reliability. Because in this example there is almost no asynchronous code at all. Everything is sequential. There is no synchronization. There is nothing. Just a channel and just coroutines. That is all. And inside each coroutine the code is synchronous. And you do not even need any structural concurrency. The task is solved because when the channel is destroyed, an exception is thrown and the coroutines will terminate together with the rest of the code. Of course, if you add automatic process restart, it becomes a bit more complex, but the code is still synchronous. Which is very good. Imagine a person who has never worked with async before. How hard would it be for them to write this code? --- Ed