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 <internals@lists.php.net>; 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 <internals@lists.php.net>; 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: <rob@bottled.codes> 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 <internals@lists.php.net>; 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 <internals@lists.php.net>; 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: <xms:vb7KZ0Sr3A9CEsMXI4uuRx46-sVjn1x9lJeazeneXCCJFy8w1Tgdzg> <xme:vb7KZxwgeiXa_lYjGXQ5jjW-tZcY_yxTJD1t3ZH4liaev57KZwXt1rArLuUSIPXfZ BD2tWVqVKNKAqrFzKo> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduuddtfedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefogg ffhffvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhs fdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpedtue ejtdethfeulefhtdelieduteelffdtudelheffgedtieehhfelieejgfevgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtth hlvggurdgtohguvghspdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: <xmx:vb7KZx0sCYc-EfNYPDO3w1QAVhnZqPFnUv6TA0jjeJtkmAPhYcqtrQ> <xmx:vb7KZ4BCKdJtPHFxCc8opgtioSrAUvEakj8DQ4x5O54idEjqqm3d7w> <xmx:vb7KZ9gUlBcMh-ll21P-zj6ytekg0Uak6yc2l63rsivZVjZkib5RNA> <xmx:vb7KZ0qMzRxZtjN6LK8Ht8l3eBjcIpJsYzQmmyxZ_rCOgmZYuggJlw> <xmx:vb7KZ9LPEqadXzOajIzJ_s3Bo2B1VGRn_k5yWEnWpp_JDZRaaAYMwSps> 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: <mailto:internals+help@lists.php.net list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net> list-post: <mailto:internals@lists.php.net> 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: <CAMW7n8BfpxOV5bd309T-A71mXO=1T8DoaO8c2__oNKUQ1-XrKw@mail.gmail.com> References: <CAMW7n8AJckEDzhGv9BdjNhq8zAdCqb4HsVr56vGi+izw50X6Dg@mail.gmail.com> <9964db8c-0ffe-43d5-8246-47fc76b07180@app.fastmail.com> <CAMW7n8CM7oBfXCDsKtV4hTFs40UmLCU3183WjYE2exLNqKDWLQ@mail.gmail.com> <78a03dd0-fd4a-4f4a-ad8a-37e5704f06fc@app.fastmail.com> <CAMW7n8C-Z18MKhyDX2+ofg70cRbwWOk=YWDAZpKtfLZsFVVRng@mail.gmail.com> <23e162f6-54b0-4564-9d79-7b3bdc3d1ab5@rwec.co.uk> <CAMW7n8A_KM6W0NHk_Ypd2PGdJZbi0quxwGvM27pf-U-YOe-RGw@mail.gmail.com> <36cee7e3-2ef8-4f96-a72e-e67a99e5f9bb@rwec.co.uk> <CAMW7n8BGbjfCrPeiWO-mucYO3i8x=3XkcULXTjPbP7p3aV7rKg@mail.gmail.com> <779046a0-7c70-45a9-82c4-7c31c502cec2@rwec.co.uk> <CAMW7n8DXoKjXaZZ0HsSyA4k_+sY5iRyKhipwsVZvF2Ux+tFnww@mail.gmail.com> <CAMW7n8BfpxOV5bd309T-A71mXO=1T8DoaO8c2__oNKUQ1-XrKw@mail.gmail.com> 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 <!DOCTYPE html><html><head><title></title><style type=3D"text/css">p.Mso= Normal,p.MsoNoSpacing{margin:0}</style></head><body><div><br></div><div>= <br></div><div>On Fri, Mar 7, 2025, at 09:48, Edmond Dantes wrote:<br></= div><blockquote type=3D"cite" id=3D"qt" style=3D""><div dir=3D"ltr"><div= class=3D"qt-gmail_quote qt-gmail_quote_container"><div><br></div><div d= ir=3D"ltr"><div dir=3D"ltr"><div>><br></div><div>> =0A=0AAs f= ar as I know, all current SAPIs follow one of two patterns:<br></div><di= v>><br></div><div><br></div><div><p>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.<br></p><p>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 <b>Scope</b>. The scope depends on the <b>TOKEN</b> and reflects the = following entities:<br></p><ul><li><b>User Profile</b><br></li><li><b>Co= mpany Settings</b><br></li></ul><p>We have two implementation options:<b= r></p><ol><li>Pass the user profile and company settings to every method= .<br></li><li>Use some static variable to make the semantics shorter.<br= ></li></ol><p>When the application runs in separate processes, there are= no issues. What do we do?<br></p><ol><li>Pass the <code>UserProfile</co= de> object into DI.<br></li><li>Pass the <code>CompanySettings</code> ob= ject into DI.<br></li></ol><p>Everyone is happy. If it=E2=80=99s a <b>lo= ng-running</b> 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.<br></p><p>However, this model will not work if each re= quest is processed in a separate coroutine. There are two possible solut= ions:<br></p><ol><li>Pass the <b>"environment objects"</b> explicitly th= rough function calls (<i>I=E2=80=99d like to see developers doing this a= nd staying in a good mood</i>).<br></li><li>Use something else.<br></li>= </ol></div></div></div></div></div></blockquote><div><br></div><div>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:= <br></div><div><br></div><div>- you need "volatile" injections,<br></div= ><div>- you need "singleton" injections,<br></div><div>- and you need "p= er request" injections.<br></div><div><br></div><div>"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).<br>= </div><div><br></div><div>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.<br></div><div><br></div><div id=3D"s= ig121229152">=E2=80=94 Rob<br></div></body></html> --6aadce3278f54a0daebfda84a562fccb--