Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122120 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76525 invoked from network); 5 Jan 2024 12:19:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2024 12:19:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1704457176; bh=VlQeW5fjvz/spQ07SLNTSUe4+1kI/YEeAPiH9OWdsfk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Br/z60h9ZYJB/aF/GsoTanWYbeaGy9RhcIACe5Ox0W6sycga+8cSP6gJPKkXpnH3r k2GQ0qWu6sNx6lUAqO5D59ZTDE4PY97ndvvzz6DIGxX1CthnsDpam2vMhwC3iILdYt SKBAMdaGRWniZmzJu1rIMgu4iu6XPEuV/RWMz7nYSE8jcScyyH8Qjmz1u+e0PQceeB s5o99Lq8zOHd5E+7HDCe04dgmTDAS2x+kbERRzZDAqoT5HT8YAdZy0c8aD8rmStvTU 6GlLLm6cDmmZOx1oYFCiYjTYv5Y//FtdjtxIMAipVf7WypyuuG7eD6gI8sswnQwTDW I7f5KteRjVl0Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7BAA9180058 for ; Fri, 5 Jan 2024 04:19:35 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) (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 ; Fri, 5 Jan 2024 04:19:34 -0800 (PST) Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-59600dbfb58so687111eaf.1 for ; Fri, 05 Jan 2024 04:19:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704457142; x=1705061942; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VlQeW5fjvz/spQ07SLNTSUe4+1kI/YEeAPiH9OWdsfk=; b=cUQc4bc+MU/jWSEkw1poQxHXklOut372UIIV5l8I77f34VlJ/d0eJkWngIhdijFGH9 BWuOxPnjnv+fLXueJNLcucuyY1WJS/Wiu/Z9tBAvyloKxW6/fec/HzHowPQKNtBjLDw5 8FPf/C2c8+pV1eI63PWEVtIYylGaGePqrvWrs7gP6wtHaeqE0Kbv77n0oGR5p11iOo4a FF5MhVIy/0GJUs9kvKEpkfa8wDK4KZApcl+f9Rq89sfIttPGfcyJCvKn2flVdCwm9msL BHLSFkpItF1GcuwjlSyfhPkjH2/8/BM03t47NtvtWN/4m8QC6JLpHefNmRLWT8at8pmB PckQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704457142; x=1705061942; h=content-transfer-encoding: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=VlQeW5fjvz/spQ07SLNTSUe4+1kI/YEeAPiH9OWdsfk=; b=w5CFt9eJhqe9Cxx7YojWR7nnVdOrYgoTVX3SFSb+m1OB1KVTNoyqUmrbv3QnQsp2SZ zTc8yiPX3OanBb0Fmb4vljdRtUtuUymTnoTxxs9QLcxxi+Y842QHmh9nrqdtY7BTxD+L 49btx776IiQTqvbMt6kz89iPh24g2gnG4faZId16k+Q1Q/gXuMaFAZbtplu4XYGQWYGa 15YEeoRGlhERx3DqLawaw2uCEwkXanazcEzyqX8a8ldpFjRQaoxT8uRv42peBLoxxNys Mhrxrv7eo6Jtn+470v39WMY5K3a0vADJxk1BsQGEKZrBWyU/4Mt7c0iOE4vOltJMUuRu OzRg== X-Gm-Message-State: AOJu0Yy6iuvaL15lPnmYcq8bs/bAJna0jlkKOVWfR1I9Ghh2w/vPrsNA JhzzPKem+wcK9RN25cB2h3xM2z7II7bPqXaAA+308Tf6KqY= X-Google-Smtp-Source: AGHT+IGXI2Hzc78itNjZZW6MCuFlrBDw1LN20OvEy1+lsAb2reQX14H5bsVXuG/x99nwSc5VoFooMbTZNGRaaXl+f1s= X-Received: by 2002:a4a:4bc3:0:b0:596:390a:9c4d with SMTP id q186-20020a4a4bc3000000b00596390a9c4dmr570100ooa.6.1704457142197; Fri, 05 Jan 2024 04:19:02 -0800 (PST) MIME-Version: 1.0 References: <3828a559-5dae-44d1-96ce-dff1a8b07c18@gmail.com> <99C434B3-3953-4E90-8DEA-94237332219D@gmail.com> In-Reply-To: <99C434B3-3953-4E90-8DEA-94237332219D@gmail.com> Date: Fri, 5 Jan 2024 13:18:51 +0100 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC proposal: worker mode primitives for SAPIs From: landers.robert@gmail.com (Robert Landers) On Fri, Jan 5, 2024 at 11:59=E2=80=AFAM Rowan Tommins wrote: > > On 5 January 2024 09:02:05 GMT, Robert Landers = wrote: > > I don't think they are fundamentally incompatible. If we look at > >FrankenPHP's implementation, you pass a callback that gets called when > >there is a request. > > No, you pass a callback which is called exactly once, for the next reques= t. You have to implement your own loop if you want to handle multiple reque= sts, which obviously isn't how it would work with an async event loop. > > That was one of my suggested changes: move the loop into C, so that the A= PI was "callback called for each request". This actually *adds* flexibility= on the server end, to decide how often to call that callback, do so asynch= ronously, etc. I think the goal here is to provide the basic building block: a function that takes a callable that, when called, blocks the script. Even when you have an event loop, there is some point when you call something and enter an infinite loop (the event loop), and no more of that file will be called ($app->start() or whatever). This is _that function_ for all intents and purposes. You can implement your own event-loop using do/while (such as in FrankenPHP), or a SAPI can call it in a loop for you. The bedrock is in core PHP, providing a standardized way of setting this up ... obviously, there are also SAPIs out there doing their own thing, and there always will be. > > Globals is how this works (atm) > > It's how it works for native SAPIs. It's not, as far as I know, how any w= orker system other than FrankenPHP has implemented its API. Every other imp= lementation I've seen, whether async or not, passes in some form of request= data to the callback, with the exception of RoadRunner, which gives the da= ta as a return value from a "get next request" function. Nearly every library in existence knows how to use these globals (including 30 years old legacy code). There are also the unwieldy PSR request/response containers for which there are dozens (if not hundreds) of implementations. It would be fantastic if there were already an extension-based implementation that could be adopted into php-src; though I feel like that is a separate conversation. > So, the second suggested change is to standardise on the most common patt= ern of passing parameters to a callback, rather than the unusual one of pop= ulating and clearing superglobals. As a bonus, this pattern works with both= non-async and async workers. > > > > changing the signature of the callback is generally backwards compatibl= e > > This is true in the narrow sense that it won't cause any fatal errors. Bu= t if you write your application assuming that it will run in an environment= where globals are populated for you, it will not run in an environment whi= ch no longer populates those globals. This is easy to handle from C. If the callback takes an argument, don't fill in the super-globals. It allows legacy apps to be slowly "upgraded" while allowing newer apps to take full advantage of a SAPI. That's how I would implement it, anyway. There is also something to be said to go "all the way" and just abandoning legacy apps, but that doesn't feel like something PHP would do. > >Changing the underlying implementation in php-src when there are > >native fibers/event loops probably won't even change anything (since > >that was exactly how they were designed). > > Sounds great! So we don't need to wait to put that implementation in plac= e then. > > > > >But holding up the entire conversation ... > > There is no reason whatsoever to hold anything up. The suggestion is not = "don't implement any worker API until we have an async implementation", it'= s "a worker API sounds great, let's implement one that looks like this". > > Yes, it might take slightly longer to define some new array structures, b= ut we're talking about a few hours work to give us a much more flexible sys= tem, not weeks of complex engineering. > > If the proposal is "copy some code from FrankenPHP into php-src, which no= body else will want to use", it's pointless; if it's "standardise an API wi= th some enabling code", then *of course* we want to spend a bit of time des= igning that API. That's fair. I was taking this push-back from you and others as, "No, we don't want this unless we can have all these other things," so thank you for clarifying that. I can largely agree -- I use amphp + fibers extensively in another project, so seeing more love for concurrent servers would be nice. Maybe I saw it that way because I have a fairly deep understanding of the shortcomings with fibers/async-php and see the amount of work required to support what you are proposing. However, if we go into the design with the concurrent server story in mind, I think we can create something much better than what is available from FrankenPHP. > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >