Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126548 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 B22551A00BC for ; Mon, 3 Mar 2025 10:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740997076; bh=sK2fXGk0NlPTtoOFSwywlg7k6YM9MZ99WgQ5wRqyjfM=; h=From:Subject:Date:References:To:In-Reply-To:From; b=LXJ3izZ4qMPXlYrZ/Ixz1h4Xo3ntVm1lMn9/ZeoF7pAXdGAvzCJnrh6eij4zQ5mOf UbsSPoh/1Q3u9iexXzqkG1Cj4S1yWlSWxDRQsJpE/VTvGX23eAagecV4DiBpbsHrl4 n1OKzlR8Kz6J0P6Rs5Wj7xn+BMWk9chQk57egguAvscUvmAsF8gOuxk53bi7uaic7Y swOGKpNO2lgdDCYyCb9bKmwEbNgqIry0kysMRYZFz+YbtdQqgOLM1jEdRQ/dVxIRxI I9W5uObA1/kRJpwMx/taRWYJ65AhY9rBoeEIbUTaKIlTAzb/1aAQIoh4QvP8UvF3En Msl6aH1VodmVA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8C3781801D7 for ; Mon, 3 Mar 2025 10:17:52 +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=0.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from sender4-of-o52.zoho.com (sender4-of-o52.zoho.com [136.143.188.52]) (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 ; Mon, 3 Mar 2025 10:17:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1740997226; cv=none; d=zohomail.com; s=zohoarc; b=fOtrO5EeKE0Wso1tj8kQXWaUXbVCYIQR7qWvM7L61jDwdu9UNL8C30Z1JX9IeyAelULFfjHZLtt/7A6prXjtgdVqFqepten87vWcE7f/2xh/+2H3r7gNN6LalP8U8PkNRz6AVJT0KHEyi38PQZIKBDRwdFBZOsbbDjBTmclseb8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1740997226; h=Content-Type:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=6C/iJ3bdBuhIr7uhm/wOIl+C4/n2QPiaNgnmqFzwtKw=; b=Bs6f3c6GBYuWk+Z4Ej2VA9mtpPzk5JVKIi/mDZY2Kg/Qp+FCZ02HlLLjYdhxig3s84fOZLPDoZSYct7NBuWVTLPqRRnTrX6Ar8iPgiFqauf+JO6aY4bkA9f4psSIDAcJkTeMKBVOr6Wh71DO603+k1a4RF59QdPBhWxwoiVaZRw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=daniil.it; spf=pass smtp.mailfrom=daniil@daniil.it; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1740997226; s=daniil; d=daniil.it; i=daniil@daniil.it; h=From:From:Content-Type:Mime-Version:Subject:Subject:Date:Date:References:To:To:In-Reply-To:Message-Id:Message-Id:Reply-To:Cc; bh=6C/iJ3bdBuhIr7uhm/wOIl+C4/n2QPiaNgnmqFzwtKw=; b=OG+Mf4Ww9FtPS6Fc5u/G+YMYMnuLAllIP1WyqC1Zmri1hoisf9bEuAjIE9U/K/HO QpVGKADvHD6zfU++TE7PjQNVoTlut3wHczZ2EAcrUM9hx41YsnZwEvNGieed6CnzIlK cEFMsOOKidNj/NJKhAGpgmPHEgzPBnRc+wdkb/hY= Received: by mx.zohomail.com with SMTPS id 1740997223371740.523802168788; Mon, 3 Mar 2025 02:20:23 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_6822597E-085E-436E-A98C-1AA4A9FDB30E" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\)) Subject: Re: [PHP-DEV] PHP True Async RFC Date: Mon, 3 Mar 2025 11:20:10 +0100 References: To: internals@lists.php.net In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3826.400.131.1.6) X-ZohoMailClient: External From: daniil@daniil.it (Daniil Gentili) --Apple-Mail=_6822597E-085E-436E-A98C-1AA4A9FDB30E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, > Any Fiber can be canceled at any time, and there is no need to use = explicit Cancellation, which I personally find an inconvenient pattern.=20= >=20 As a heavy use of both amphp and go, cancellations (contexts in go) are = absolutely needed, as a fiber may spawn further background fibers in = order to execute some operation, just cancelling that specific fiber = will not cancel the spawned fibers, unless a bunch of boilerplate = try-catch blocks are added to propagate CancellationExceptions.=20 A nicer API should use only explicit cancellation objects, as this = pattern of preemptive implicit cancellations (i.e. a fiber may be = cancelled at any point via cancel()) is super dangerous IMO, as it can = lead to all sorts of nasty behaviour: what if we cancel execution of a = fiber in the middle of a critical section (i.e. between a lock() and an = unlock() of a file or a database? What if unlocking() in the catch = (CancelledException) block requires spawning a new fiber as part of the = interaction with the database?). Consider also the huge amount of CancelledException blocks that would = have to be added to handle state cleanup in case of premature implicit = cancellations, as opposed to explicit cancellations that only throw when = we ask them to: there=E2=80=99s a reason why golang, amphp & others use = explicit cancellations. Another thing I=E2=80=99m not happy with is how unless the scheduler is = launched, all code executes in blocking mode: this seems like a super = bad idea, as it will hold back the ecosystem again, and create a split = in the project similar to JIT (i.e. a separate =E2=80=9Cexecution = mode=E2=80=9D with its own bugs, that get fixed slowly because few = people are using it, and few people are using it because of its bugs). The main reason given in the RFC (Code written without using the = Scheduler should not experience any side effects) makes no sense, = because legacy code not spawning fibers will not experience concurrency = side effects anyway, regardless of whether the scheduler is started or = not. A thing I would love to see, on the other hand, is for Context to become = a =E2=80=9Cprovider=E2=80=9D for superglobals such as $_REQUEST, $_POST, = $_GET, and all globals in general (and perhaps all other global state = such as static properties): this would allow to very easily to turn i.e. = php-fpm into a fully asynchronous application server, where each request = is started in the same thread (or in N threads in an M-N M>N execution = model) but its global state is entirely isolated between fibers. Regards, Daniil Gentili - Senior software engineer=20 Portfolio: https://daniil.it Telegram: https://t.me/danogentili= --Apple-Mail=_6822597E-085E-436E-A98C-1AA4A9FDB30E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi,

Any = Fiber can be canceled at any time, and = there is no need to use explicit = Cancellation, which I personally find an inconvenient = pattern. 

As a heavy use of = both amphp and go, cancellations (contexts in go) are absolutely needed, = as a fiber may spawn further background fibers in order to execute some = operation, just cancelling that specific fiber will not cancel the = spawned fibers, unless a bunch of boilerplate try-catch blocks are added = to propagate CancellationExceptions. 

A nicer = API should use only explicit cancellation objects, as this pattern of = preemptive implicit cancellations (i.e. a fiber may be cancelled at any = point via cancel()) is super dangerous IMO, as it can lead to all sorts = of nasty behaviour: what if we cancel execution of a fiber in the middle = of a critical section (i.e. between a lock() and an unlock() of a file = or a database? What if unlocking() in the catch (CancelledException) = block requires spawning a new fiber as part of the interaction with the = database?).
Consider also the huge amount of = CancelledException blocks that would have to be added to handle state = cleanup in case of premature implicit cancellations, as opposed to = explicit cancellations that only throw when we ask them to: there=E2=80=99= s a reason why golang, amphp & others use explicit = cancellations.

Another thing I=E2=80=99m not = happy with is how unless the scheduler is launched, all code executes in = blocking mode: this seems like a super bad idea, as it will hold back = the ecosystem again, and create a split in the project similar to JIT = (i.e. a separate =E2=80=9Cexecution mode=E2=80=9D with its own bugs, = that get fixed slowly because few people are using it, and few people = are using it because of its bugs).
The main reason given in = the RFC (Code written without using = the Scheduler should not experience any side = effects) makes no sense, because legacy code not spawning fibers will = not experience concurrency side effects anyway, regardless of whether = the scheduler is started or not.

A thing I = would love to see, on the other hand, is for Context to become a = =E2=80=9Cprovider=E2=80=9D for superglobals such as $_REQUEST, $_POST, = $_GET, and all globals in general (and perhaps all other global state = such as static properties): this would allow to very easily to turn i.e. = php-fpm into a fully asynchronous application server, where each request = is started in the same thread (or in N threads in an M-N M>N = execution model) but its global state is entirely isolated between = fibers.

Regards,
Daniil Gentili - = Senior software engineer 

Portfolio: https://daniil.it
= --Apple-Mail=_6822597E-085E-436E-A98C-1AA4A9FDB30E--