Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128878 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 6FA291A00BC for ; Tue, 21 Oct 2025 13:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761053619; bh=m/GCovmuFWpp0QZRR4/5ixFMc1LNkFi7mHni3Gf8Vmw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KBawbNpb5g5ljMqnefE6NJNCQS6bZd7xnNEVfOJKXJj67iDntxP2xUmv/wlcz5fHe 9I68xejbwLCuqGwQ1BHG8iWMFqJMaBb0VXfwZWehZ50wjus8kzTxFfHSxgNfe4/dFA 5+dDlE5z7715V2WkpnsMpI9g6/Cjd/BWPo/VuQ+ktFlwNOxKKgzMxvDzXoCkF9xpX+ o7Ra38Ld8/tv/Px3nDQMneHWDmU08GUo/tvWgOqAp0CfocxgaprpS35JBVEz/n5LJ7 EZdynpAAVpoYOu05zrfz6zaT2eSOq6T/ZdyyUUzfyQXdpL6IMVwIr8BN7LBBs3ut4T 17n4yvAMFFDmQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 94B4418006E for ; Tue, 21 Oct 2025 13:33:38 +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-ua1-f47.google.com (mail-ua1-f47.google.com [209.85.222.47]) (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 ; Tue, 21 Oct 2025 13:33:37 +0000 (UTC) Received: by mail-ua1-f47.google.com with SMTP id a1e0cc1a2514c-932c3aa32f3so1034365241.2 for ; Tue, 21 Oct 2025 06:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761053612; x=1761658412; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BYMvngGGy+xSwNsp0NnfT8C/P/fNtJCDBPE5R5GbTCI=; b=np63cRksa57gJHFd8tBKvD9A0E+hDZUxPyN7ZUbn3362ueMLOFHOrlv2Nc+Ng2Q99Q xyytrlkJ5ssxRkupWX43xOJmUia5L+rhfw1GfUr7G4PKHRyDhiuRwOGjTP9zERcTX3J1 dF1DxCSKBh134diR20Y1IL2rJFMgX34XxSUG+G0gc63VFkYW9cyl0l4d9TXCeypmXBwe pC/baJS+I9vryKnClLrgS3434Yfn2zRLb+PZUX7yTbBHLlQ/qDM+6+kl+cn62T7vqbHn e9Tpyv3UZQsYp4pP7eHI80zOBiHks5ntoXdAW16IdW2lIVXv/zc238Bvg8yUS/eKpS/R iSBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761053612; x=1761658412; h=content-transfer-encoding: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=BYMvngGGy+xSwNsp0NnfT8C/P/fNtJCDBPE5R5GbTCI=; b=pq2TU/+r2NBtEtrYD8TAnTNS3AIT+fPJ0bEeqVaKtOdOr5nkznF5Rq415eWGjnHtj5 VY18hqfv82NwjPZJp/LvU0vH09l9rhu6sxYchFo9qGjOmNgOhlpGzV2NtgezYfd5TSjK 9kGp4ZVMgMq6aszjC+ZRerb/9K9RHKMoQyn59C1/iLjo/oHne1jM9sIPtk7yD8dZSpuq QKCJAGyOSBeG8T3KDYWqo3sgorQA8A8XK5ns7hLCy8nR3nrCzbWsS7nSgTi1InrUqBKH R+AK+gRJQ9BT/EWq7iwQLxwWnbYqEg0KChl8a8fw+R4UtvRahGBozlbWiRmieZPuoOkK qqKw== X-Gm-Message-State: AOJu0Yxa227Baay7cEEMKFRrOpoBjSKyx91vGoN/rXg+shIVg2DGtrbU 2vBJdHys1ItgpcZ0ROWyCehKIOPDCgXgGAwUWIb+QUUY2hj4f8w3S7Rp+ycBRU8fR6W/TUbArry r2sasjcO/CUaRZJTVJuKOFlWGPtqTR6VF9bRnWp7NpA== X-Gm-Gg: ASbGncsf0OkYf0yJaKHK4l4noPEMjECIWdAWKqQ8vlvNBIXZvTO8Ht7s944rUTyUVxC jVf87rQhB/hFcIJX0u1K9Agz8ENDqGNTZQ6LNf+1PUzC4KSovOStpLTuZ6BNEIRILl2CKi4tZuZ rrRFRmSFdjAw5UVbWOuH5QrxoDIMt+ruo+CMQJxdZEBuuszItvAQbDHJeE9Q4WYhDqpPTNYiIvm AB4z4sC9WH/pToiQNrzcH1DUs/OTGSaPidpIG11qJvECh0FWxqaxEjfBaqpu+WkaHXWQ+T/MdXG vgdkkAcio1ybPdM= X-Google-Smtp-Source: AGHT+IHi2tL1yHY13Vv9nCeDEjQCpqoyUMc6gKLQi+Dtgp7bswR5z0cZ0o51uamowr2wGy4y2pIoTim4GPgV4B85kt0= X-Received: by 2002:a05:6102:370b:b0:5d5:f6ae:74b6 with SMTP id ada2fe7eead31-5d7dd62ac9dmr5310524137.42.1761053612009; Tue, 21 Oct 2025 06:33:32 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <0e4e39d6-9cc9-4970-92e0-2463143b4011@app.fastmail.com> In-Reply-To: <0e4e39d6-9cc9-4970-92e0-2463143b4011@app.fastmail.com> Date: Tue, 21 Oct 2025 16:33:21 +0300 X-Gm-Features: AS18NWBGJ5q1ClJ4EMCUTQDjhh9oSzw6W5wsNsUljY7_prF5-3cF6gG3-JTjJh8 Message-ID: Subject: Re: [PHP-DEV] PHP True Async RFC Stage 4 To: Rob Landers Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) > When I await(), do I need to do it in a loop, or just once? It depends on what is being awaited. On one hand, it would probably be convenient to have many different operations for different cases, but then we make the language semantics more complex. > Coroutines become Future that only await once, while Signal is something = that can be awaited many times. At the moment, only such objects exist. It=E2=80=99s hard to say whether th= ere will be others. Although one can imagine an Interval object, there are some doubts about whether such an object should be used in a while await loop, because from a performance standpoint, it=E2=80=99s not very efficient. > But the example setChildScopeExceptionHandler does exactly this! The Scope-level handler does not interfere with coroutine completion. And it is not called because the cancellation exception is "absorbed" by the coroutine. > Further, much framework/app code uses the $previous to wrap exceptions as= they bubble up, If a programmer wants to wrap an exception in their own one let them. No one forbids catching exceptions; they just shouldn=E2=80=99t be suppress= ed. > Async\isCancellation(Throwable): bool Why make a separate function if you can just walk through the chain? > Minor nit: in the Async\protect section, it would be nice to say that can= cellations being AFTER the protect() are guaranteed, and also specify reent= ry/nesting of protect(). Like what happens here: That=E2=80=99s a good case! Re-entering protect should be forbidden that mu= st not be allowed. > Also, if I'm reading this correctly, a coroutine can mark itself as cance= led, yet run to completion; however anyone await()'ing it, will get a Cance= llationException instead of the completed value? If a coroutine is canceled, its return value will be ignored. However, of course, it can still call return, and that will work without any issues. I considered issuing a warning for such behavior but later removed it, since I don=E2=80=99t see it as particularly dangerous. This point requires attention, because there=E2=80=99s a certain =E2=80=9Cf= lexibility=E2=80=9D here that can be confusing. However, the risk in this case is low. > Allowing destructors to spawn feels extremely dangerous to me (but powerf= ul). These typically -- but not always -- run between the return statement = and the next line (typically best to visualize that > as the "}" since it r= uns in the original scope IIRC). That could make it 'feel like' methods/fun= ctions are hanging or never returning if a library abuses this by suspendin= g or awaiting something. Launching coroutines in destructors is indeed a relatively dangerous operation, but for different reasons mainly related to who owns such coroutines. However, I didn=E2=80=99t quite understand what danger you were referring to? Asynchronous operations, as well as coroutine launching, are indeed used in practice. The code executes properly, so I don=E2=80=99t quite see what risks there could be, apart from potential resource leaks caused by faulty coroutines. > async.zombie_coroutine_timeout says 2 seconds in the text, but 5 seconds = in the php.ini section. Thanks. > What is defined as "application considered finished?" FrankenPHP workers,= for instance, don=E2=80=99t "finish" =E2=80=94 is there a way to reap zomb= ies manually? The Scheduler keeps track of the number of coroutines being executed. When the number of active coroutines reaches zero, the Scheduler stops execution. Zombie coroutines are not counted among those that keep the execution running. If PHP is running in worker mode, then the worker code must correctly keep the execution active. But even workers sometimes need to shutdown. > it would be good to specify ordering and finally/onFinally execution her= e Doesn=E2=80=99t the RFC define the order of onFinally handler execution? onFinally handlers are executed after the coroutine or the Scope has comple= ted. onFinally is not directly related to dispose() in any way. When dispose() is called, coroutine cancellation begins. This process may take some time. Only after the last coroutine has stopped will onFinally be invoked. In other words, you should not attempt to link the calls of these methods in any way. > Maybe something like Async\isEnabled() to know whether I should use fiber= s or not. Good idea!, considering that such a function actually exists at the C code level. > Is this "same exception" mean this literally, or is it a clone? If it is = the same, what prevents another code path from mutating the original except= ion before it gets to me? It=E2=80=99s the exact same object that is, a reference to the same instanc= e. So if someone modifies it, those changes will, of course, take effect. > Is there also a timeout on Phase 1 shutdown? Otherwise, if it is only an = exception, then this could hang forever. That=E2=80=99s true! A hang is indeed possible. I=E2=80=99m still not sure = whether it=E2=80=99s worth adding an auxiliary mechanism to handle such cases, beca= use that would effectively make PHP =E2=80=9Csmarter=E2=80=9D than the programm= er. I believe that a language should not try to be smarter than the programmer if the application runs in a certain way, then it=E2=80=99s probably meant to be that way. > - Sometimes you use AwaitCancelledException and other times CancellationE= rror. Which is it? The old exception name apparently hasn=E2=80=99t been updated to the new on= e everywhere. > Nit: the error message has a grammatical error: "Cannot create a fiber wh= ile an True Async is active" should be "Cannot create a fiber while True As= ync is active"? > Thanks!