Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126619 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 BE6421A00BC for ; Fri, 7 Mar 2025 09:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741340196; bh=bEVrblAJrVdlJkmi0udcHiw7wLS9qBkRHFe6+zQteQc=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Q5KUrdaGeGyimGxyM7tAj3kzXsKc1JKwx6VqXjaG17UUptSlsN00WOl6/WnttBw2J lXJyKLVInfGtsTemHND4HUkpOtFAg3dhNWp2LFuLvf6UM1XSejy33yz99lubXXQVpD 4zIb2IOLON9GAVy71LrHd84qNDlfD6GwEMbq+DdX+q21dlVcLlNRGdYt6MMoihgjWK cTPPuliNrduAT1la6HyfubURONsiB1Pixgy7cXDekzC4lHf0ebrJJZwrschMPV2f68 MWu2MZJb5VcJjfUdKRkLo98U71zvesIWj7Kq6F0o3thhxRD6poaItB9p0Kay6IsjDF 6Nw3GrgahZT4A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D340F18005B for ; Fri, 7 Mar 2025 09:36:34 +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=-1.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (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, 7 Mar 2025 09:36:34 +0000 (UTC) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id 95E4711400E1 for ; Fri, 7 Mar 2025 04:39:09 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-11.internal (MEProxy); Fri, 07 Mar 2025 04:39:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm2; t=1741340349; x=1741426749; bh=Nw/zvTCEDZ C+zNXCRl2rS2+0r7O5Q+wKduJT8g8oJ4s=; b=SHuqFznjGBay497LJIOo1GsXIX 7yRtV+Z9juO5Bd9fJskMejWDh2gWa1/F/uZdl5A5tOquJP/vwY2M1XPoCW7DuYx2 zP3oYuWaGg/6lQu2mymdzt+d2NQCuRMrgJAILASDEm1s7nwDBa6wgHoaItK/B/DA lCqydCiLvDST9YseTuVh9nRIfkwoIvigwy2L7I1BzVE1XoxgydBbBydAiNRXhM7N Zxbz23FsuQbB0mZWRBZ2Q/CktteHz9x7jXBytVnWbMaTq5yAlFvuOSK1svzo0+HY o4nZA+YJzpZdKykGcHDG12taJn38GpR5bSKT96BFszD+DGCbj87gfPRmJnjw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= 1741340349; x=1741426749; bh=Nw/zvTCEDZC+zNXCRl2rS2+0r7O5Q+wKduJ T8g8oJ4s=; b=QL3bSNu8RaQH6G+81hioKaQnQtOIJCzZ2soeIZ9HcC4AaaGiqWp 1hw92/hnxEqZQW4qmC7LSSxzLgjOgU4umoYpIHaO6aco7Pntt+UeC4kR7KXr116W JDoMDf1CGsvvE27TMU0Hv78+JHFIB9NZ8/9naVCQxAa2IBiJDq/p01scrRRYjMSt ueC8DsCydjxdZ7gMABPrmhk5c/f/DsYVztqHBhutHpoW0f4CYgsKnBZLWxz7rb5T tJy9tdT4tQ95Yw2EHXp1LtFbK63Ko6G7V7EiAVWuWyHhY7uHfsuKVW+dDj9tV0Th vyi6E3q/f5K4J3/MD2waxKJ5wO9wi5oAGFw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduuddtfedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefogg ffhffvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhs fdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpedtue ejtdethfeulefhtdelieduteelffdtudelheffgedtieehhfelieejgfevgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtth hlvggurdgtohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 27128780068; Fri, 7 Mar 2025 04:39:09 -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: Fri, 07 Mar 2025 10:38:47 +0100 To: internals@lists.php.net Message-ID: <1084afab-e3d7-4fcb-9e09-63c159bc9e10@app.fastmail.com> In-Reply-To: References: <9964db8c-0ffe-43d5-8246-47fc76b07180@app.fastmail.com> <78a03dd0-fd4a-4f4a-ad8a-37e5704f06fc@app.fastmail.com> <23e162f6-54b0-4564-9d79-7b3bdc3d1ab5@rwec.co.uk> <36cee7e3-2ef8-4f96-a72e-e67a99e5f9bb@rwec.co.uk> <779046a0-7c70-45a9-82c4-7c31c502cec2@rwec.co.uk> Subject: Re: Fwd: [PHP-DEV] PHP True Async RFC Content-Type: multipart/alternative; boundary=6aadce3278f54a0daebfda84a562fccb From: rob@bottled.codes ("Rob Landers") --6aadce3278f54a0daebfda84a562fccb Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, Mar 7, 2025, at 09:48, Edmond Dantes wrote: >=20 > > > > As far as I know, all current SAPIs follow one of two patterns: > > >=20 > It seems that my example, although taken from real life, is more of an= anti-pattern. Let's take a real example that is not an anti-pattern. >=20 > There is a B2B CRM built on services. Services are classes instantiate= d in memory only once via DI, and all that. We process requests. Request= s are executed within a logical *Scope*. The scope depends on the *TOKEN= * and reflects the following entities: >=20 > =E2=80=A2 *User Profile* > =E2=80=A2 *Company Settings* > We have two implementation options: >=20 > 1. Pass the user profile and company settings to every method. > 2. Use some static variable to make the semantics shorter. > When the application runs in separate processes, there are no issues. = What do we do? >=20 > 1. Pass the `UserProfile` object into DI. > 2. Pass the `CompanySettings` object into DI. > Everyone is happy. If it=E2=80=99s a *long-running* process, everyone = is twice as happy because the already loaded services and resolved DI ar= e reused multiple times for handling requests. Memory copying is reduced= , and for fast requests, we get a nice performance boost. This is especi= ally pleasant for users with a good internet connection. >=20 > However, this model will not work if each request is processed in a se= parate coroutine. There are two possible solutions: >=20 > 1. Pass the *"environment objects"* explicitly through function calls= (*I=E2=80=99d like to see developers doing this and staying in a good m= ood*). > 2. Use something else. This sounds like you are not using DI meant for fibers/multiple requests= at the same time. DI used in large projects like the one that comes wit= h Symfony is NOT compatible with this model. These are the basic require= ments for DI that needs to handle multiple requests on long-running scri= pts: - you need "volatile" injections, - you need "singleton" injections, - and you need "per request" injections. "Volatile" injections are injections that provide a new one every time y= ou ask for it and "per request" injections are singleton, but only for t= he current request (every request gets a new one and only one for the li= fetime of the request). The only "services" running between requests and= not new'd up every request are "singleton" injections. These are statel= ess services providing generic interfaces (such as sending emails, notif= ications, etc). This is how .NET does it as well (just with different names), and as far= as I know, absolutely no DI library in PHP does it this way, and only p= rivate, custom built DI does it this way; the ones that are using fibers= already. =E2=80=94 Rob --6aadce3278f54a0daebfda84a562fccb Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Fri, Mar 7, 2025, at 09:48, Edmond Dantes wrote:

>
> =0A=0AAs f= ar as I know, all current SAPIs follow one of two patterns:
>

It seems that my example, althoug= h taken from real life, is more of an anti-pattern. Let's take a real ex= ample that is not an anti-pattern.

There is a B2B CRM built on= services. Services are classes instantiated in memory only once via DI,= and all that. We process requests. Requests are executed within a logic= al Scope. The scope depends on the TOKEN and reflects the = following entities:

  • User Profile
  • Co= mpany Settings

We have two implementation options:

  1. Pass the user profile and company settings to every method= .
  2. Use some static variable to make the semantics shorter.

When the application runs in separate processes, there are= no issues. What do we do?

  1. Pass the UserProfile object into DI.
  2. Pass the CompanySettings ob= ject into DI.

Everyone is happy. If it=E2=80=99s a lo= ng-running process, everyone is twice as happy because the already l= oaded services and resolved DI are reused multiple times for handling re= quests. Memory copying is reduced, and for fast requests, we get a nice = performance boost. This is especially pleasant for users with a good int= ernet connection.

However, this model will not work if each re= quest is processed in a separate coroutine. There are two possible solut= ions:

  1. Pass the "environment objects" explicitly th= rough function calls (I=E2=80=99d like to see developers doing this a= nd staying in a good mood).
  2. Use something else.
  3. =

This= sounds like you are not using DI meant for fibers/multiple requests at = the same time. DI used in large projects like the one that comes with Sy= mfony is NOT compatible with this model. These are the basic requirement= s for DI that needs to handle multiple requests on long-running scripts:=

- you need "volatile" injections,
- you need "singleton" injections,
- and you need "p= er request" injections.

"Volatile" injectio= ns are injections that provide a new one every time you ask for it and "= per request" injections are singleton, but only for the current request = (every request gets a new one and only one for the lifetime of the reque= st). The only "services" running between requests and not new'd up every= request are "singleton" injections. These are stateless services provid= ing generic interfaces (such as sending emails, notifications, etc).
=

This is how .NET does it as well (just with di= fferent names), and as far as I know, absolutely no DI library in PHP do= es it this way, and only private, custom built DI does it this way; the = ones that are using fibers already.

=E2=80=94 Rob
--6aadce3278f54a0daebfda84a562fccb--