Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78545 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87781 invoked from network); 1 Nov 2014 14:14:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Nov 2014 14:14:53 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:62174] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/F1-63593-CDAE4545 for ; Sat, 01 Nov 2014 09:14:53 -0500 Received: by mail-wi0-f180.google.com with SMTP id hi2so3279019wib.7 for ; Sat, 01 Nov 2014 07:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=UwQ3ETUtwHr0BUZiikr/h6X2H1h6SJqv0pFh1gbo5bE=; b=uiprKB33wkI9Fd9Mw24RF4POBRdDE0jSINg/134MVKCtA5H3hfWKPByT2kNDsKXWd1 qLXdHPyeVv4KLfw21jKitrPG9ywXfNXptJrCbyW1w9QtQ+1e6Iukx+9YjUex8re9nOgL K9NIec/FU97Bhqx9nBKbsGd2yTy1mtvFzrWZj2Co6sZsT4OvBaR52dazVuXxHbDz8ld+ lGH334shDU+R0SxPxMkV5VsED1jAzxF6plFzx7lGaVIEC/MAIR+/gd6H7ZQpsakb8gbU 1JdwUBus6l7DIBKEKSuMlqTYJLiHagnae53XuU2xrOI2XKA9e/gwCLZ+53QZ3nT2vPsw nQ4g== X-Received: by 10.194.201.198 with SMTP id kc6mr34195711wjc.77.1414851289651; Sat, 01 Nov 2014 07:14:49 -0700 (PDT) Received: from [192.168.0.3] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id t7sm12709499wjy.24.2014.11.01.07.14.47 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 01 Nov 2014 07:14:48 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: <5452B87B.5040009@garfieldtech.com> <0B797CE3-7AFA-4330-9A98-D3CAFC6D6072@ajf.me> <5453B114.6050400@gmail.com> <5453C250.8090803@gmail.com> <5453D6D5.2070705@garfieldtech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Sat, 01 Nov 2014 14:13:42 +0000 To: internals@lists.php.net Message-ID: <604DEB5F-35FF-46BE-9CAF-7681F0E19116@gmail.com> Subject: Re: [PHP-DEV] New Standardized HTTP Interface From: rowan.collins@gmail.com (Rowan Collins) On 1 November 2014 13:15:45 GMT, Damien Tournoud wrote: >On Sat, Nov 1, 2014 at 1:40 PM, Andrea Faulds wrote: >> > On 31 Oct 2014, at 18:37, Larry Garfield >wrote: >> > IF internals wanted to add implementation, not just improving >streams, something like the following would be much more useful: >> > >> > $request = http_get_request(PHP_STDIN); // or something >> > >> > Where $request is an object that implements the PSR-7 >RequestInterface (or at least the read-only parts of it), or something >similar. Then implementers can compose that object however they want. >> > [...] >> >> This sums up my thoughts on this very well. Nobody needs to change >how we parse the data. We just need better access to the results of the >parsing. > >Alternatively, what I would see as extremely useful would be to be >able to expose the "main loop" of the SAPI. Have a way (via an ini >mechanism) to register a callback that is executed when a requests >start processing. Essentially, similar to what is provided by WSGI >(for Python) and Rack (for Ruby). > >The default implementation would be something like: > >function default_entrypoint($env) { > php\register_superglobal($env); > php\execute_script(); >} >?> > >(with this callback executed in the scope of the new request) > >But you could override any of it if you wanted to, and that would pave >the way nicely to more advanced PHP SAPIs (possibly evented) down the >road. This is actually quite an appealing idea; it provides a stepping-stone towards an evented SAPI without pre-empting other decisions which would need to be made (such as how global and static scopes would be handled). I particularly like the idea of exposing elements of default behaviour as non-magic functions, so that you could pass some other/modified request object to populate superglobals, for instance. It could perhaps be implemented as a special function, which if present in the file targeted by the HTTP request (i.e. not via include()/require()) is called automatically, and passed a standard object providing access to the raw request. I'm not sure how the response could best be managed so that it interacted smoothly with existing mechanisms; the function could optionally return a response object, but would perhaps need access to a magic object representing the default response built with echo, header_*() etc. Waiting for the entire response to be ready before streaming it to the SAPI isn't always desirable, either; I guess these are the kinds of issue FIG have been discussing... In short, though, you would have an index.php file something like this: getQueryStringParam('action')); $custom_response = $action->process($request); return $custom_response; }