Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129219 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 73C231A00BC for ; Thu, 13 Nov 2025 13:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1763039327; bh=uD1UwQSk9tDfx+w4otqxeqS+9CKAe5wu6I+13tl3v9I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hjYwK7rAdrz7dLOxQW3MTSEb1SmNHEzgTb4rBrSj0Bk3Hyf10aOCHXEfyaftfxXFh b2DiVekUr06ab4nK3wlli04CLbHai/uewTenQJjV3ddtB/Cu8Qr0VIxTTb9gTZ9VNi F5PuHMpXb9i6kmXmHA/s0V4tLD2xf5TtZjE7ILmKRjoHsvDEq9nFxRlmGy0K+IgoZi Vu1AfluUVqTMS0xkIAjp0JjGhTpR+tbqocb2Vm+meHexWuTD9fmJQzlNNFBRFThFSV 51EnQcaue7XvlGUJJM82/FRRQenvL4EVUZee7ZIr81aOfL0sFEAUwZDy7QSdP06QTh ote2Y9AKmUkNg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C48B9180041 for ; Thu, 13 Nov 2025 13:08:46 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f46.google.com (mail-vs1-f46.google.com [209.85.217.46]) (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, 13 Nov 2025 13:08:46 +0000 (UTC) Received: by mail-vs1-f46.google.com with SMTP id ada2fe7eead31-5dd9bfba5bbso257214137.2 for ; Thu, 13 Nov 2025 05:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763039321; x=1763644121; 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=uD1UwQSk9tDfx+w4otqxeqS+9CKAe5wu6I+13tl3v9I=; b=JCoL4JDAG0wtJE5iZG8LI4dZkQ8Je14JJ/U6PBjDO5gXwTxRphCAbPqPTHeTJzNX8L g2+6ugQXPiwNKXDq3xoUrhUL8CTONaCU6Z4lc+FzpmAGj/AM600mIjFLlI4H1PjqhYi0 GpiO+a8C38JLiVsJnkaLRjPTNHGZG4hQmJKhVtNx1FSgnDUOUuLMonh4lj0YRDHdpfGq bvPWHsoFY/vU2o9W8Eoj9ODePL65ILDtPHPytctjvv79+INcjbs9TjKi1sz5ofcKCUAT Hd9vz0LiiAGZ9UPEP30qwFmcZabaxEJA9zfvq312oOly+XEO+lGpBmssyQoe3EuGphfc HCFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763039321; x=1763644121; 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=uD1UwQSk9tDfx+w4otqxeqS+9CKAe5wu6I+13tl3v9I=; b=nKt85GziFbGupTU7poKdyb7IJuoCYXMnw45daq+tWRc1/CnLMpd0C6wLz4R29mb8h8 P0sY42kJ3sA6wWbS8HovtiVRcp/sY59T6NSNLjzyGtQ7LuoORL4+k4OWUte1c548sCak peFpKVXAXZJy1WOd51yiB73tXDZS+blA/qAdfUxbCohTUYskihm7E7uOzAKHj5BvR7Qz QK85U39/X2G1TdlQkNPeEFij9D34V9PQq3rMV40WEmWrug1F1AR0dn4xbYDgHw+JQHjy ab027CStUVTmMSEZjP1BzqLivHTdpmDEYVB+K4bsI5E+y9VmafdKtEEeG7INu2tvH/K4 Rp4A== X-Gm-Message-State: AOJu0YwQlw5RU8qlp3/2ayygYDlWDIDNRnPokXoLeDzKOF/UiVlqiEZ7 g3nBxWG/FXJsewQ4wNw7S76cefe69hELpZJ1NtmAP2kjgnS4OyU406mgZBINt2qoKlzlDBc+vhx 6Mpmq7Al+MQx/a22rOjA9HpbyftFSuHw= X-Gm-Gg: ASbGncsSemTMbvsgNcNhoSsQ5S4Xxk2eKo4idtfRWg7j1EFsed0zpbmUC+C/LkthFRt fiIdyRILDLv6BgPevSh7IlTJV1WUwPyctwkvjR8hzk5HwfOPLyk2jBcKvYa/KT53Mp1dUnj3UsI n0JaFzCouubbBe1Wi+JA6f9u0ArPTTrvg7A5H3OQdiY0ojz9I58xa8bFyAGSdxOK1XDIR152s0P 2CJ8AQvBpLh6elIUMa6pWZcUhoB8DGusZaFDi+pXjk/nftQsNWnRuY8McRKj39hGaYpyk1sdVqv SBIigAadjcxA5VA= X-Google-Smtp-Source: AGHT+IFfJ07bL6fZU65eDJkr2EOnpEday39+AFdJ6dOkJNgnEHxP0lqyid6S8HKjwF+dm6R3QzdYzHd+R29xXOSa0ng= X-Received: by 2002:a05:6102:950:b0:5db:da81:2541 with SMTP id ada2fe7eead31-5de07d4cb93mr1967002137.12.1763039320705; Thu, 13 Nov 2025 05:08:40 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <697c56c5-78bf-407a-a884-74ee150e992c@bastelstu.be> In-Reply-To: <697c56c5-78bf-407a-a884-74ee150e992c@bastelstu.be> Date: Thu, 13 Nov 2025 15:08:29 +0200 X-Gm-Features: AWmQ_bl3tN0RzzDeQOfutKARzWSdUNWEXQCnnZVxr3XmpVu7qZftdtsfI8zcyHc Message-ID: Subject: Re: [PHP-DEV] Re: PHP True Async RFC Stage 5 To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: php internals , Jakub Zelenka , Larry Garfield Content-Type: text/plain; charset="UTF-8" From: edmond.ht@gmail.com (Edmond Dantes) Hello. Mini Faq: https://github.com/true-async/php-true-async-rfc/blob/main/faq.md Text here: ## Executive Summary: What This RFC Proposes This RFC proposes adding **built-in concurrency support** to PHP through two core components: ### 1. Coroutines via `spawn()` Launch any PHP function as a lightweight coroutine that can be suspended and resumed: ```php use function Async\spawn; use function Async\await; $coroutine = spawn(file_get_contents(...), 'https://php.net'); $result = await($coroutine); ``` ### 2. Non-blocking I/O Functions **50+ existing PHP functions** automatically become non-blocking when used inside coroutines: - **Database**: PDO MySQL, MySQLi operations - **Network**: CURL, sockets, streams, DNS lookups - **Files**: `file_get_contents()`, `fread()`, `fwrite()` - **Process**: `exec()`, `shell_exec()`, `proc_open()` - **Timers**: `sleep()`, `usleep()` **Key principle:** From the developer's perspective, these functions work identically to their synchronous versions. The difference is that they suspend only the current coroutine instead of blocking the entire PHP process. See full list: https://github.com/true-async/php-async#adapted-php-functions ### What This RFC Does NOT Propose - **No changes to existing synchronous behavior** - code without coroutines works exactly as before - **No new syntax keywords** - uses function calls (`spawn()`, `await()`, `suspend()`) - **No changes to Fiber API** - Fibers and True Async are mutually exclusive by design - **No structured concurrency primitives** - covered in separate [Scope RFC](https://wiki.php.net/rfc/true_async_scope) ## General Questions ### Q: What is the main goal of this RFC? **A:** The RFC aims to provide a standardized way to write concurrent code in PHP without requiring developers to rewrite existing synchronous code. The key value proposition is that existing code works **exactly the same** inside a coroutine without modifications, unlike explicit async/await models. ### Q: How is this different from Fibers? **A:** Fibers and True Async serve fundamentally different purposes and cannot coexist: **Fibers:** - Low-level symmetric execution contexts - Programmer explicitly controls switching (`$fiber->resume()`, `Fiber::suspend()`) - Direct access to execution stack management - Suitable for building custom scheduling solutions **True Async:** - High-level asymmetric coroutines - Automatic switching managed by the scheduler - Transparent to the developer - Designed for business logic, not infrastructure **Why they can't work together:** 1. **Resource conflicts**: Both manage the same low-level resources (execution context, CPU stack) in incompatible ways 2. **Architectural incompatibility**: Mixing symmetric (Fibers) and asymmetric (coroutines) models creates unpredictable behavior 3. **Abstraction level**: Fibers expose low-level primitives in a high-level language, violating the "Strict Layering" principle **Why not map Fiber::suspend() to Async\suspend()?** This would create a leaky abstraction: - Fibers require explicit scheduling decisions (who to resume? when?) - True Async scheduler makes these decisions automatically - Mixing both models would break scheduler guarantees and lead to race conditions - The execution models are fundamentally incompatible (symmetric vs asymmetric) If you need Fibers' explicit control, use Fibers. If you want automatic concurrency for I/O-bound applications, use True Async. Attempting to unify them would result in a solution that's neither simple nor safe. ### Q: Isn't this just Fibers 2.0? **A:** No. While both deal with execution contexts: - Fibers require explicit switching and manual control - True Async provides automatic scheduling and high-level primitives - They solve different problems at different abstraction levels - They are mutually exclusive by design ### Q: Can I use this with FPM? **A:** Yes! True Async works in all execution modes including FPM. The reactor activates within the context of `php_request_startup/php_request_shutdown()`, requiring no SAPI modifications. ### Q: What about `exit` and `die`? **A:** They always trigger **Graceful Shutdown** mode: - All coroutines in globalScope are cancelled - Application continues execution without restrictions to shut down naturally - This allows proper cleanup operations ### Q: Do I need to rewrite my existing code? **A:** No. The main value of this implementation is that existing synchronous code works inside coroutines without modification. You can gradually adopt async features where beneficial. ### Q: How does this RFC affect I/O functions? **A:** From the coroutine's perspective, I/O functions **do not change their behavior** they work exactly as they always have. However, functions that previously blocked the entire PHP process now only suspend the current coroutine, allowing other coroutines to continue executing. ---- Best regards, Ed