Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129034 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 06FAF1A00BC for ; Fri, 31 Oct 2025 22:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761951598; bh=XJ18oo+yXiA4UMnutM3mGMOOZ078LWLt5jZKTmVdOaM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=YSqtujNpOHMppTsqdJlBIJ0OaU1vXk0GvTm33SPyZPfUKsruQuxAMcrK1vngQGL1H XVdIjxYbVyz5SP8AWat6+OaC92h1bUpW2V0Z5MbftZO+Ay/FhYztPC3TIw5n3NdE19 pB1sgDoHx5zwEOLP1CUCXvaU35sUAjAeilzGhxkHyj3lNG0rmzUAj7L5njE3SmHZZS DcDKculbI+TSnJqlTVNrlhpbMnOiNW0sy0Ti/8b9Ylt7ySTbd4Dhn5MGwyjeEJKsLr T5+CouM0+JTIqGcNEGQ3Us1CUwoxCBOYQ+922F+pvalN1fj+ZxNfPSyPqAdZ9OAzrt w9EkzmAZXaHTA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A338D1801D9 for ; Fri, 31 Oct 2025 22:59:55 +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_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail.yourprovider.de (mail.yourprovider.de [157.90.159.104]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 31 Oct 2025 22:59:43 +0000 (UTC) Received: from [192.168.178.35] (xdsl-78-35-193-36.nc.de [78.35.193.36]) (Authenticated sender: dennis@birkholz.biz) by mail.yourprovider.de (Postfix) with ESMTPSA id 5D8D29C4AE for ; Fri, 31 Oct 2025 23:59:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dennis.birkholz.biz; s=default; t=1761951577; bh=XJ18oo+yXiA4UMnutM3mGMOOZ078LWLt5jZKTmVdOaM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=X6piUcopVNYfzQPLpCnbYIwfZZaV1hYFTtGy6Mhr5x6bv4g67ZNmZ86lhma2JGYTf BJfCg/e7VRYRwU+SPWlDz3KMEyZZekXAWEq8tDeAG5mKeqkcRVI2Ed3OypGgdDbBId TEAEf88G2BLvZkszzQaFhQfsOEPW9HTpLpX1VSdlED+cR/hfPMJDJ4fY5ijbdabyZH VSzQFRx0zPDv7V0njetpV5H/7KmvP34GvOKX8neoN/Gpi3rYLrjPPAWaA018Iehy7t imY9AwGQPkXzoTBM6Lri+WrqOkBgRiSvUQ3lj/4P3w37KCe2HYl5+g+jILRzMxuNRb airszkdy9GX2w== Message-ID: <2441aa9c-41c8-4ce1-b9c0-67136e5f97da@dennis.birkholz.biz> Date: Fri, 31 Oct 2025 23:59:37 +0100 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] PHP True Async RFC Stage 5 To: internals@lists.php.net References: Content-Language: de-DE, en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit From: php@dennis.birkholz.biz (Dennis Birkholz) Hi Edmond, Am 30.10.25 um 9:19 AM schrieb Edmond Dantes: > Hi > > 1.5 RFC: > https://wiki.php.net/rfc/true_async first of all thank you for investing so much time and effort into improving PHP. The True Async RFC changed a lot in the past iterations and removed a lot of related but tangential topics. I really appreciate your willingness to adapt to get the best possible outcome. What I now see is as far as I understand essentially a Fiber 2.0 RFC so I wonder if it would not be better to improve the available Fibers instead of creating an incompatible second mechanism. The Coroutine class is essentially a Fiber class that can be cancelled and restricted by a cancellation awaitable. The Fiber class could get startWithTimeout($timeout, ...$args) and resumeWithTimeout($timeout, mixed $value = null) methods as well as a cancel() method. It wouldn't be a Fiber in the pure compsci way any more but I am willing to accept that if it prevents us from having two ways for (semi) cooperative multitasking. The part about how the Awaitable and FutureLike interfaces work is very unclear to me. They are there but they do not describe how they could be used in a truly multitasking fashion. That is somehow open to the Scheduler/Reactor which are not described to reduce the complexity. The RFC as it is allows to `await(new Coroutine())` which is syntactical sugar for `$fiber = new Fiber(); $fiber->start(); while (!$fiber->isTerminated()) $fiber->resume();` So a followup RFC would need introduce this additional mechanism into these interfaces. Also I do not really understand why the "cancellation" is an awaitable. If the provided awaitable is itself some infinitely blocking Coroutine (e.g. `while (true) {}`), how can the scheduler run the actual Coroutine and the "cancellation" awaitable to determine whether the Coroutine should be cancelled or not? As long as there is no multithreading, this does not make sense for me. In addition, what happens if a Coroutine is suspended and is restarted again. Is the cancellation awaitable restarted? Or just continued? I am really skeptical if the current RFC is the right way to go, establishing a Coroutine and Awaitable and FutureLike interfaces in competition to the existing Fiber. I would rather see a step-by-step plan with gradual improvements like this: 1. Propose some changes to Fiber so it can be interrupted after a timer expired and it can be cancelled. 2. Add a unified polling mechanism for all kinds of IO events (timeouts and signals included) like Jakub's "Polling API". 3. Enhance the Fiber class so it can expose a PollHandle/Pollable that it is currently waiting on, either as a property of the Fiber (Fiber::$pollHandle) or as a `Fiber::suspendPolling(PollHandle $pollHandle, mixed $value = null)` method. 4. Now internal IO methods can be changed to start a pollable Fiber instead of blocking the execution if they are started in a specific way (e.g. by a then introduced spawn() call). 5. With all that in place, userland can now create their own Scheduler/Rector. The Core could also include a simple default implementation used the PollContext/PollWatcher in addition with a scheduling policy for other Fibers. Kind regards Dennis