rfc:request_response

PHP RFC: Server-Side Request and Response Objects

Quoting Rasmus:

PHP is and should remain:
1) a pragmatic web-focused language
2) a loosely typed language
3) a language which caters to the skill-levels and platforms of a wide range of users

This RFC should move PHP forward following his vision. As said by Zeev Suraski “Consider only features which have significant traction to a large chunk of our userbase, and not something that could be useful in some extremely specialized edge cases […] Make sure you think about the full context, the huge audience out there, the consequences of making the learning curve steeper with every new feature, and the scope of the goodness that those new features bring.”

Introduction

From time to time we've all heard the complaint that PHP has no built-in request object to represent the execution environment. Userland ends up writing these themselves, and those are usually tied to a specific library collection or framework. The same is true for a response object, to handle the output going back to the web client. I've written them myself more than once, as have others here.

After doing some library and framework research it looks like there is a reasonably common subset of request/response functionality across all the userland implementations. That functionality also appears useful to non-framework users.

I next put together a userland implementation of the common subset, which John Boehr then used as a reference point for the C version. It is PHP 7.x only. The proposal below is the result of that work.

Proposal

This extension provides server-side request and response objects for PHP. These are not HTTP message objects proper. They are more like wrappers for existing global PHP variables and functions, with some limited additional convenience functionality.

This extension defines two classes in the global namespace:

  • ServerRequest, composed of read-only copies of PHP superglobals and some other commonly-used values, with methods for adding application-specific request information in immutable fashion.
  • ServerResponse, essentially a wrapper around (and buffer for) response-related PHP functions, with some additional convenience methods, and self-sending capability.

The full extent of all functionality is described at https://gitlab.com/pmjones/ext-request , and is available as a beta for installation and testing at https://pecl.php.net/package/request .

Backward Incompatible Changes

None expected.

Proposed PHP Version(s)

Next PHP 7.x.

RFC Impact

To SAPIs

None expected.

To Existing Extensions

None expected.

To Opcache

None known.

New Constants

None.

php.ini Defaults

None.

Open Issues

Make sure there are no open issues when the vote starts!

Unaffected PHP Functionality

The remainder of PHP should remain unaffected.

Future Scope

Possible support for HTTP/2 and server push.

Proposed Voting Choices

This counts as a language change, so a supermajority is required.

Patches and Tests

The C code for the extension and tests are at https://gitlab.com/pmjones/ext-request .

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature

References

Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/request_response.txt · Last modified: 2017/01/06 17:23 by pmjones