Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122073 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90918 invoked from network); 30 Dec 2023 19:49:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Dec 2023 19:49:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1703965772; bh=On/9CvVB/o8EZLAbvFPWgKgyPnnBe2J1Nqxs6P2IGNs=; h=In-Reply-To:References:Date:From:To:Subject:From; b=m1AByFFL7LVB2jVlICLgksXi/2BgXX1qifITpxFVebsUGihn1FdmqvPyqrec+PGPZ PY5CGXb0NOk/toDhzHBf0SB7CBKwc39MT76o3YEp79G0Dv6+sTAi2Sjb7DIQ6v6zS4 kbiO4ns83REQqth/+VLdbY1hQCaN9fUBiZfx0S7ZyXB8wA5y451gTTnWzE/8hTmYaL RyZEV65l490miUAmgYwtr1EcTSpul3zi3XqSkgyKSn63dOeLKwIqRFVQ9wh3GZeY+W LGcZJriwqlvIhbvh7lG5JtTA+hE+W+XL0cM7XBk5FXvSasGzvcoNGLeypZwy4AqgCR A4cbW4PHS9H7Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4A1C418004D for ; Sat, 30 Dec 2023 11:49:31 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 ; Sat, 30 Dec 2023 11:49:30 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 119893200A15 for ; Sat, 30 Dec 2023 14:49:00 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Sat, 30 Dec 2023 14:49:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; 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=1703965740; x= 1704052140; bh=eOYNfAYpCMVZ/VERwxNJJvC/9krA0G7f2YhHTW901to=; b=j Wn1vPi1M3dEo6nYtVury7aU6K23vQqdj6gGAxZXBWDpINdd2IbO48a6kON9g/KcS 6kLMJmUNIHxCsSpdcexJZ4IwkbESQsBHtwSyVk2BNHLdH/F1VxL8pNKpELLkHVwO 5u3P337Zslw0HUcBHdl3oV/KyTgMX75/nVvMIXNY6uY/mXgLRCpvgn/Ih26nsLpm VepGmsiUO4qGkoxVav4F+u24ifCNwRcXFCDF9Hos24CTx3/JS3b5J6d+qD3FwTL1 txVqdpBcibtN+YML2oaRtKocX5sQg2KCa4vQr7IG7M8zTFQblrI06q+TXrtc3Lo2 AL+qDvmUZBPEJen9oHH/Q== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1703965740; x=1704052140; bh=eOYNfAYpCMVZ/VERwxNJJvC/9krA 0G7f2YhHTW901to=; b=GOEa7NITpFyz/IR2if7YZyNd5wShw7oZun0OLMo6kysT UPddi0Re8JnmDMqiNRb+ars8zWzFm1UuKKRwrMC9UbkeKBhNH2OgRfYcnne8gKwW Mb5khHhHlgpbaxv4LEEjC6JD8gf/9iJ6PvxorL6gl8qjHLuuIwmedEqKM/bVVlYp ljJHQ1qUidatmMZrsaRvQ+M3+hbUcgaxoDz33NChow8S9iuf95aHUhWL/5giFfnx sTGjnm2Vkty3d6oWX3/wnctGYu0wJ2oyh/XQUOCI+XHXG4jfnIzzS3oAIucQnpXg wVePh272aRCC2YKJP40Qf+e274v5SZL3aqKJJIOolA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdefhedgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepkeffvdejfeejkeeuudeghfduhfejffduheeugedt ffetfeeiheegteekfefgffetnecuffhomhgrihhnpehfrhgrnhhkvghnphhhphdruggvvh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghr rhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 282B61700093; Sat, 30 Dec 2023 14:49:00 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1364-ga51d5fd3b7-fm-20231219.001-ga51d5fd3 MIME-Version: 1.0 Message-ID: <8fb6672c-06e9-4f74-b2f2-cd1a265c75a5@app.fastmail.com> In-Reply-To: <7F63D301-1A46-49AA-9140-F64543E902C5@gmail.com> References: <5060b986-2e5a-46e4-9c83-763e5b155e83@gmail.com> <6f7815b9-80cc-4e08-819a-49dca090116f@gmail.com> <7F63D301-1A46-49AA-9140-F64543E902C5@gmail.com> Date: Sat, 30 Dec 2023 13:48:39 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] RFC proposal: worker mode primitives for SAPIs From: larry@garfieldtech.com ("Larry Garfield") On Sat, Dec 30, 2023, at 4:53 AM, Rowan Tommins wrote: > On 30 December 2023 09:59:07 GMT, Robert Landers > wrote: >>For this to happen in PHP Core, there would need to be request objects >>instead of a global state. > > Again, the representation as objects isn't a key requirement. Python's > WSGI spec simply has a dictionary (read: associative array) of the > environment based on CGI. The application might well turn that into a > more powerful object, but standardisation of such wasn't considered a > pre-requisite, and would actually have hampered ASGI, where not all > events represent an HTTP request. > > The key requirement is that you have some way of passing the current > request and response around as scoped variables, not global state. > That's essential for any kind of concurrent run-time (async, > thread-aware, etc). > > An event / subscriber model fits well with that: the local scope for > each request is set up by an invocation of the callback with defined > parameters and return value. > > Funnily enough, the example of a worker script for FrankenPHP does both > things: it sends each request to the same application "handle" > callback, passing in the super-global arrays as parameters to be used > as non-global state. https://frankenphp.dev/docs/worker/#custom-apps So > really all I'm arguing is that a few more lines of that PHP example be > moved into the C implementation, so that the user only needs to provide > that inner callable, not the outer while loop. So you're suggesting something like: $app->initializeStuffHowever(); set_event_handler(Closure $handler); // Script blocks here until a sigkill is received, or something. I think there's an important distinction that is getting missed in the above discussion, beyond the push-vs-pull question. FrankenPHP, as I understand it, pre-boots multiple worker processes, keeps them in memory, and then handles each request in its own process. Swoole, Amp/React/Revolt, and friends have only a single process running at all, and make use of async to simulate multiple simultaneous requests, a la NodeJs. That means mutable global variables in the FrankenPHP model still won't leak between parallel requests, whereas they absolutely would/do in a Swole/Revolt world. I'm not going to call one of those better or worse (I don't have enough experience with either to say), but they are different beasts for which first class support would be different SAPIs either way. They're not mutually exclusive thanks to Fibers (which mean you don't need the entire call stack to be async), but you would want to pick one or the other as primary runner mode of an application. Let's keep that in mind when making comparisons. The Franken-model is closer to how PHP-FPM works today, which means that is easier to port existing code to, especially existing code that has lots of globals or hidden globals. (Eg, Laravel.) That may or may not make it the better model overall, I don't know, but it's the more-similar model. All that said, the idea of allowing a "persistent HTTP handler process" SAPI, "persistent Queue handler process" SAPI, and "persistent cron handler process" SAPI (or whatever combination of persistent processes) to all run side by side with the same code base but different entry point scripts is... Hot. If we can do something that would enable that kind of runtime model, I am very much here for that. --Larry Garfield