Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122074 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92871 invoked from network); 30 Dec 2023 20:09:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Dec 2023 20:09:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1703967012; bh=SNouRLvZyAvO8a4ZYcGBlUTqnvespKvdqDnVX21l4ws=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=REfjpryzf7RWB1Vg3GrhY8YvMkg5SzZ1Q5C20CaNIDNURDcMtgL2Xgo38q4xT2zyQ GCNlRxNKmrNFxxapuZ+CJGWcYt/J/1N/F8KYLgsgDh4H/ktsUFu81Y6obG2fWDJcW3 abRN0uoOeQ6JYX4PtzWGrGTm6+L9CSe/XZvpYgMmfHitiOQO/tezzkY2nqZB4/nqQy w4xoNmql8bL6eh+6DznqB/z7SMl23fZp4C27Jn8QqbH96FzB88okdvdVNyoNB+CEuC SM6oHmlAY0fdXgxGmJArPnQlgIXXfdBESIAxvxAmlpAU3JjWfTt8EhQoiyADyWmX6H GIkxlOxJ2tb6w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6FCE918004D for ; Sat, 30 Dec 2023 12:10:11 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 12:10:10 -0800 (PST) Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3bb7344a0e1so6727949b6e.0 for ; Sat, 30 Dec 2023 12:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703966982; x=1704571782; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=l8O6Y/QV9ubLgtsJzW0CE1CXY/SDUzAvFNYvMuPzbAY=; b=efWU9SWdjERaRKxMf7xNitmVlcWJrOhOn/anNDdDgrBcNZPTJJVdAqOPnApoh+IPI9 bIxpkktGoCujxHfmNE+iUDhbfSFksH7W0ppLZ7zIpXMY0J4IhlNDBtGTr+GMmmKuSuVv oxvkd7ErGwGTltQiL1ZOwofmHfQr55HgoSVvDMRZhvWFnU3DNKkLnNvXUEc/+9A2Hd47 aIKSFa88DH9WLu5zO4bAfBK24bowp54X4JIy0gn8LPRAGx2VZnyqRv1dvJpeVY6TbZUI 03EzK9pdWcPKSDStaclVcJGKE6/g87Lde5BHWYiT2PbDA6pOt5mdqUmJ+4RBbMmaURWD n1WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703966982; x=1704571782; h=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=l8O6Y/QV9ubLgtsJzW0CE1CXY/SDUzAvFNYvMuPzbAY=; b=Qc/M5pGVYaadBwq23kAJCgZMKnFMMAn9qwVCzF04wmmDtWDY8ENGC/d4CbL1ZXcuu9 kOp6faH4naKl/Ht298Y8fd6ZiieUcUP9BxefqHwlY4H0J25bNMASfGtQBs+eN7MFX1kA tvrv/fCplSWAjzgpwySaaMR5p80YVid3+RwPLIbGWKZVz0TNX+UmZ7lbSMMFyLPpz+2S Uofm+OLP3qIEzSCXW1VzC2qKLBhOAqq5zKz3OFULDJf73c89ewb5cquLE6DxJXElmC4F OcYpED6TtVCuIPjOIFT2oNG2W5FpdMlEwZTH3wnwQB2bwoCbcH9rRyqc6AAbHGYk7coI EYVQ== X-Gm-Message-State: AOJu0YywIIL1hwBmT85dZi4P/it1GvrdR2JoZ+iCucUSKLcSujo7plL+ yl6z2BqHHPnSTPd32fDjDH/uR1mQuBucIYukZb4= X-Google-Smtp-Source: AGHT+IEoYfQh1B+GRMkjRkoaxGS9aicjyKZ+/BuCB0OPt47MVJ/pRLsvtlhK+arYP1gde2rVapOVbPklpbBnOk49ZCY= X-Received: by 2002:a05:6808:17a7:b0:3b9:f0dc:4407 with SMTP id bg39-20020a05680817a700b003b9f0dc4407mr17067270oib.69.1703966981629; Sat, 30 Dec 2023 12:09:41 -0800 (PST) MIME-Version: 1.0 References: <5060b986-2e5a-46e4-9c83-763e5b155e83@gmail.com> <6f7815b9-80cc-4e08-819a-49dca090116f@gmail.com> <7F63D301-1A46-49AA-9140-F64543E902C5@gmail.com> <8fb6672c-06e9-4f74-b2f2-cd1a265c75a5@app.fastmail.com> In-Reply-To: <8fb6672c-06e9-4f74-b2f2-cd1a265c75a5@app.fastmail.com> Date: Sat, 30 Dec 2023 21:09:29 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000a62c70060dbfba38" Subject: Re: [PHP-DEV] RFC proposal: worker mode primitives for SAPIs From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000a62c70060dbfba38 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Larry, sob., 30 gru 2023 o 20:49 Larry Garfield napisa=C5=82(a): > 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 stil= l > 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 maki= ng > 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 lot= s > of globals or hidden globals. (Eg, Laravel.) That may or may not make i= t > 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 handl= er > process" SAPI (or whatever combination of persistent processes) to all ru= n > 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 runtim= e > model, I am very much here for that. > What you wrote sounds like some good points (as usual). I'm not an expert (yet!) but was playing around with some callable trying to mimic ASGI https://github.com/brzuchal/asgi-playground/blob/main/app.php#L26-L37 What I think currently (maybe too hurry, but...) is that this kind of approach is flexible enough to handle in easy way many SAPIs which identify to app their capabilities, and the app decides how and what can handle `$scope['type']` in the example code. I know there is a Runtime library, that tries to integrate Symfony/Laaravel to many SAPIs, but as far as I understood the discussion went to figure out if there is some kind of standard approach that could be shaped under the PHP umbrella. Maybe this is just a temporary fascination about ASGI solution, could be. If this is not in the scope of interest of anyone then forgive me, I won't bother anymore. Cheers, -- Micha=C5=82 Marcin Brzuchalski --000000000000a62c70060dbfba38--