Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126605 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 9E7F51A00BE for ; Thu, 6 Mar 2025 19:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741287926; bh=M0KUOwrucs/tSrrWgNXJZUDbH29CDjen8ev5rO+fPoI=; h=Date:From:To:In-Reply-To:References:Subject:From; b=OSa8Xj3zO1uO92R4oCZ8VGByon1hoPSO8oBd0MFDl+HSVUc/FjPWoRHkc/x8l/lTd iSJk+DLnF9AdY/OpHx/+8nGvvn04/Hx5ZoLvycxHShGKC1a3dzrohsCzL9t43Z0QUL 8wUx1Cqq3LjWmomEdhwKUn2jgImduRHPH46VbHESGDnDvUHQzPqHrmU0nUTjSMlnjR olWQkry6NJOe8wT2fPmBSO7Ekmc35wNIHcaMloFXvKWL3Jg4axOukeGiWmSUcwBh5w mITo5OMn/iVW5fCb1yh9WQG064Ma9nlSdgBGj6TFL2w3mCJH7lT44qS654A52UOnB7 KE2tgjFSTFPOA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 495D21804C7 for ; Thu, 6 Mar 2025 19:05:22 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (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, 6 Mar 2025 19:05:20 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 886E12540196 for ; Thu, 6 Mar 2025 14:07:55 -0500 (EST) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-04.internal (MEProxy); Thu, 06 Mar 2025 14:07:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1741288075; x=1741374475; bh=LE0hGIYatgUKt/hQf6pxa b6P1W6K00F278od6fErR34=; b=QrwMDHsiQB3iIJugpkcvrD5kT5/21U4RuxP32 8Lgm9EJ4eTjyGrPPtmlORzMuzLR8n36n60vfs1SNP3JNNo7THfj3sZHOZquVWCo+ PCfydiDGGyozvT3Gm+F0mvvhgCoFFZs0AAyJJF3RG/59AVLTsHh6HABthT35YqMb c2ULQuPPi9Kwx1oGiOBCGVFOOvnR70SYGDPQI1junLGaPO4zCQ+2C/MPXIk6uMmw Y8P5ixaHkS+Iiijelwe6jkFu16+k68lfpuMbalw7MeQFGfs+JOuy7nJvayB/5yCT nKMaGtqH1MyTs0DtN0ytkjn+CsyshSgPKf5m4w2SNlTx1mPVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1741288075; x=1741374475; bh=L E0hGIYatgUKt/hQf6pxab6P1W6K00F278od6fErR34=; b=rpHbItDGhekZjzs3a 8y8QPkweUvVCrimslDJov3wdt5WTCifqqgdHTI5FZUk2dlF70ri3GAvmP9naDoqn ajONdCy+RFx7LUy6ac2GbrHfuXA9DBwuV5YqxzzoKCeFf3Y73WFJcArwSOKiJR5C HNjVaYrZxI9Q1rCisurvD6uAILQ0jxW+WKSPhpKmHh6iuB0/jSeibTFXKQvaojEb Y0BZHknQ7ZjdAB4UVAjEtRSWrf7hwF39NiHrfHVgZwwVV//Yga+aqmcu/v54GfT7 OtD473Op+GK53zQ6etWw/C/JqmOQPq9MIhnBeVstupCJJZZtf6Fs7X6yA1uUsA8e L2QAA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddutdekheehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthhqredtredt jeenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrh hfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeekgeeuveeivdejgfei hffftdffueevfeehfedtvdffhedvgeehgeegtedtvddtgeenucffohhmrghinhephhhtth hptghlihgvnhhtqdhruhhnrghshihntggtthiguhhrlhhithhsjhhushhtrghprghrrghm vghtvghrthhophgrshhsrdhhohifnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhn sggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvg hrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 188B929C006F; Thu, 6 Mar 2025 14:07:55 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 06 Mar 2025 13:07:34 -0600 To: "php internals" Message-ID: <08c8ad0b-e8f4-46e3-99f0-b80748d40b89@app.fastmail.com> In-Reply-To: References: <9964db8c-0ffe-43d5-8246-47fc76b07180@app.fastmail.com> <78a03dd0-fd4a-4f4a-ad8a-37e5704f06fc@app.fastmail.com> Subject: Re: [PHP-DEV] PHP True Async RFC Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Thu, Mar 6, 2025, at 2:52 AM, Edmond Dantes wrote: >> One key question, if we disallow explicitly creating Fibers inside a= n async block,=20 >> can a Fiber be created outside of it and not block async, or would th= at also be excluded? Viz, this is illegal: >> > Creating a `Fiber` outside of an asynchronous block is allowed; this=20 > ensures backward compatibility. > According to the logic integrity rule, an asynchronous block cannot be=20 > created inside a Fiber. This is a correct statement. > > However, if the asynchronous block blocks execution, then it does not=20 > matter whether a Fiber was created or not, because it will not be=20 > possible to switch it in any way. > So, the answer to your question is: yes, such code is legal, but the=20 > Fiber will not be usable for switching. > > In other words, Fiber and an asynchronous block are mutually exclusive= .=20 > Only one of them can be used at a time: either Fiber + Revolt or an=20 > asynchronous block. > > Of course, this is not an elegant solution, as it adds one more rule t= o=20 > the language, making it more complex. However, from a legacy=20 > perspective, it seems like a minimal scar. > > (to All: Please leave your opinion if you are reading this ) This seems like a reasonable approach to me, given the current state. A= t any give time, you can have "manual" or "automatic" handling in use, b= ut one has to completely finish before you can start using the other. W= hether we should remove the "manual" access in the future becomes a ques= tion for the future. >> // This return statement blocks until foo() and bar() complete. > > Yes, *that's correct*. That's exactly what I mean. > > Of course, under the hood, `return` will execute immediately if the=20 > coroutine is not waiting for anything. However, the Scheduler will=20 > store its result and pause it until the child coroutines finish their=20 > work. > > In essence, this follows the parent-child coroutine pattern, where the= y=20 > are always linked. The downside is that it requires more code inside=20 > the implementation, and some people might accuse us of a paternalistic=20 > approach. :) See, what you call "paternalistic" I say is "basic good usability." Aff= ordances are part of the design of everything. Good design means making= doing the right thing easy and the wrong thing hard, preferably impossi= ble. (Eg, why 120v and 220v outlets have incompatible plugs, to use the= classic example.) I am a strong support of correct by construction / m= ake invalid states unrepresentable / type-driven development, or whateve= r it's called this week. =20 And history has demonstrated that humans simply cannot be trusted to man= ually handle synchronization safely, just like they cannot be trusted to= manually handle memory safely. :-) (That's why green threads et al exi= st.) >> That is still dependency injection, because ThingRunner is still tak= ing all of its dependencies via the constructor. And being readonly, it= 's still immutable-friendly. >>=20 > > Yeah, so basically, you're creating the service again and again for=20 > each coroutine if the coroutine needs to use it. This is a good=20 > solution in the context of multitasking, but it loses in terms of=20 > performance and memory, as well as complexity and code size, because i= t=20 > requires more factory classes. Not necessarily. It depends on what all you're doing when creating thos= e objects. It can be quite fast. Plus, if you want a simpler approach,= just pass the context directly: async $ctx { $ctx->run($httpClient->runAsync($ctx, $url)); } It's just a parameter to pass. How you pass it is up to you. It is literally the same argument for "pass the DB connection into the c= onstructor, don't call a static method to get it" or "pass in the curren= t user object to the method, don't call a global function to get it." T= hese are decades-old discussions with known solved problems, which all b= oil down to "pass things explicitly." To quote someone on FP: "The benefit of functional programming is it mak= es data flow explicit. The downside is it sometimes painfully explicit." I am far happier with explicit that is occasionally annoyingly so, and b= uilding tools and syntax to reduce that annoyance, than having implicit = data just floating around in the ether around me and praying it's what I= expect it to be. > The main advantage of *LongRunning* is initializing once and using it=20 > multiple times. On the other hand, this approach explicitly manages=20 > memory, ensuring that all objects are created within the coroutine's=20 > context rather than in the global context. As above, in simpler cases you can just make the context a boring old fu= nction parameter, in which case the perf overhead is unmesurable. > Ah, now I see how much you dislike global state! :) It is the root of all evil. > However, in a scenario where a web server handles many similar=20 > requests, "global state" might not necessarily win in terms of speed=20 > but rather due to the simplicity of implementation and the overall=20 > maintenance cost of the code. (I know that in programming, there is an=20 > entire camp of immutability advocates who preach that their approach i= s=20 > the key remedy for errors.) > > I would support both paradigms, especially since it doesn=E2=80=99t co= st much. Depends on the cost you mean. If you have "system with strong guarantee= s" and "system with no guarantees" interacting, then you have a system w= ith no guarantees. Plus the cost of devs having to think about two diff= erent APIs, one of which is unit testable and one of which isn't, or at = least not easily. Do you have a concrete example of where the inconvenience of explicit co= ntext is sufficiently high to warrant an implicit global and all the imp= acts that has? --Larry Garfield