Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122124 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90456 invoked from network); 5 Jan 2024 14:27:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2024 14:27:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1704464870; bh=vt17bqg3Gimq7XNQIqlOYQjSViLe80LfkDPoDx9G+qE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=kk8WjZfHU41re+wVmorgLMahcYZjpKhGIS0yjZedn+iqQRqUJ7g+tVwQJY5P7VYR+ z9tg7loJcaKJH6t+kFsPI/15GUwOhq3KV1GOOsBHcHA2diobzOCbfVETMmsl0Iergo lPtcezU4vxRqe3HAT6lEQsM1ZX/Zt/Jxaxb7cIwOBUSQMRxVPvBBNxmbiu7sDhdJCi mYpc3Fldiw2aMkFUUhafGYvhp0068rgvwGNIVTjCP4Y9qavAG83oB/1L3rZeUHk49x M5TBalOpHj3SbiPlCjLLErKyp2AKbgk2gjNpborONb5sUbIRh4Pt1/q+TRx1uFXd4s EP04/UA7GjcEg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 43E6F18004D for ; Fri, 5 Jan 2024 06:27:50 -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-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) (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 06:27:43 -0800 (PST) Received: by mail-ua1-f51.google.com with SMTP id a1e0cc1a2514c-7cd6377893dso91069241.0 for ; Fri, 05 Jan 2024 06:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704464831; x=1705069631; 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=aW/SHKOrSTTdvQib4iZBj6k1DKYpNgva9Q9Rn/4Sf6c=; b=VBzqV3x9iseszJ9WuZEpzwX1jzzvPcAzb9qu/Qo9ls448R7aWjWpEPvIjCyjJWrufM ReKZcMiGXKkBEq3a/0zNLWOIKSKwjA6Tpqr1KKmnUe9+wMYD8/cum+2im0/8+95ORH4u D+AZzwtyAGAWPfIM6xzL2W4a+VTmgbW6JGLVR66UoSw9e9bvkt1Mo5zmrHPURUOjyJeC 1o2Xefj91ZNYK/rb3TVIebxf7/RZbUdE3DP8WYthLJS6wYx5LQvZIAgPNYCaT0T47et+ HSiWBKoJC4uIeBh4RMEeksxnK+s5jbzbZ2xxhVUDZpzStm+rjDxfQzf6eBOiM2bElho0 93zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704464831; x=1705069631; 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=aW/SHKOrSTTdvQib4iZBj6k1DKYpNgva9Q9Rn/4Sf6c=; b=sxtWxec1DWRaYwG1xSp4HsAfLyD3NtcqLnJ812P5pO/hnraI1xJVbQNUn20sN+GjRi fCDfIq9IocoEISqK1VNr5dZ3slvQ0BDkNV1O/ZvRPqUsx+O8gInTiDjjvmJ+uiaQUWAl KM040Nx5r6/JLVIB4axBwVCSY2Yrf1Aa/8AZRljWSJhz7z0sTvMozKM5+9sYct10x0pT CGmGjNvH8ckIbUuSh9IGClXzOYyVpFwhQVPdHoZH7Cq2Sq78BKVBYgfXu278KSvGm9yA 8Kqv2AmURpXdkeB2WqDnJoniA1nail949PL2WG0xWILR9d2I7jXKISxd3/sS5Zc+ifIn fYaA== X-Gm-Message-State: AOJu0YwuD3UbMyxIKGOFYROVFGg1x0DsOVDYyU5DCnc7kru6e5GC5wVm 61u1p6GtuLwMKhpdsloJ2nXJViniQ1WcpmRdsMO0NSx1g/0= X-Google-Smtp-Source: AGHT+IHRfwVfdnmp+UXEJNqUp8tk2M7WDlsHwJgQgH8czOll+ptbhC+4nBxU8lka08yKIARPmKKhqPSEByB5s/kfbS4= X-Received: by 2002:a1f:fcc7:0:b0:4b7:49ac:df67 with SMTP id a190-20020a1ffcc7000000b004b749acdf67mr3822639vki.1.1704464830875; Fri, 05 Jan 2024 06:27:10 -0800 (PST) MIME-Version: 1.0 References: <3828a559-5dae-44d1-96ce-dff1a8b07c18@gmail.com> <99C434B3-3953-4E90-8DEA-94237332219D@gmail.com> In-Reply-To: Date: Fri, 5 Jan 2024 11:26:34 -0300 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?= Cc: Robert Landers , Rowan Tommins , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000c6d085060e33a4af" Subject: Re: [PHP-DEV] RFC proposal: worker mode primitives for SAPIs From: deleugyn@gmail.com (Deleu) --000000000000c6d085060e33a4af Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 5, 2024 at 9:40=E2=80=AFAM Micha=C5=82 Marcin Brzuchalski < michal.brzuchalski@gmail.com> wrote: > There are indeed dozens of libraries already working with PSR nicely but > IMHO > the API should provide all the necessary information in a way that allows > the construction of such objects, > but suggesting PSR with request/response objects will limit the > capabilities of worker mode API > to handle pure HTTP protocol only. > > What I'd like to say is that I believe for the initial proposal of any > eventual worker mode API > with the PSR with request/response objects should not be considered at al= l. > > Cheers > I think it's been mentioned quite a few times that it doesn't matter what gets passed to the callable function that hands over control to userland, as long as it's more functional-style and not superglobals. I also think that there's merit in both sides of the conversation between PSR-7 vs associative arrays, but I find it more important to get one of them, any of them and not halt for one or the other. PSR would make it HTTP-only, yes, but that largely benefits the PHP ecosystem to an extent order of magnitude larger than any non-HTTP format. On the other hand, being a dynamically typed language, nothing holds us from having a more simple/generic `function handler(mixed $event)` format which can also be used to process HTTP and non-HTTP events. I do prefer the more generic one as I would be interested in seeing what PHP would become with the capability of processing non-HTTP protocols made easier. That being said, I find it important to consider the quality of such an API for its users. It would end up forcing users to do the following: ``` function handler(mixed $event) { if (isset($event['_REQUEST'])) { // We are on HTTP Protocol } if (isset($event['...'])) { // This is a Websocket } } ``` If the original proposal is correct and/or my little understanding of this thread is somewhat in the right direction, it means that the introduction of a PHP function that asks its engine for the next event to process isn't a huge amount of work on PHP Internals. If that's true, I would ask that we consider making something more flexible / forgiving of errors / adjustable and evolution-friendly. Instead of striving so much for coming up with one perfect API that shall be the one true API for PHP for the next decade, we can instead consider the possibility of having multiple small APIs that can harmonically coexist. Example: Classic: ``` $classicHttpHandler =3D function (array $get, array $post, array $request, array $server, array $cookies): string|Stringable { // process incoming request in a somewhat backward-compatible friendly way return 'http response'; // Return the response similarly to how we used to `echo` it to the server. } worker_http_classic($classicHttpHandler); ``` PSR-7: ``` $httpMiddlewareHandler =3D function (\Psr\Http\Message\RequestInterface $request): \Psr\Http\Message\ResponseInterface { // Process Request } worker_http_psr7($httpMiddlewareHandler); ``` HTTP Raw ``` $httpHandler =3D function (\Psr\Http\Message\StreamInterface $raw): \Psr\Http\Message\ResponseInterface { // Process Request } worker_http_raw($httpHandler); ``` STDIN ``` $stdinHandler =3D function (SomeStdinCompatibleType $stdin): SomeStdoutCompatibleType { } worker_stdin($stdinHandler); ``` Websocket ``` $websocketHandler =3D function (string $event, mixed $data): ??? { // Process websocket incoming event } worker_websocket_event($httpHandler); ``` These APIs don't need to be ready on day one. They don't even need to be ready at all, actually. Each would end up being its own RFC. What makes the system a bit more. flexible is the api naming which follows the pattern PHP Engine Namespace (worker), Purpose Namespace (_http, _websocket, etc) and Variation Namespace (_classic, _psr7, _raw). For me personally one awesome last step would make this a PHP Class instead of procedural functions. That would be even better because we could use the Class namespace itself to version it and provide future changes without breaking what's been introduced already. --=20 Marco Deleu --000000000000c6d085060e33a4af--