PSR-7 is the FIG standard for HTTP messages in PHP. It provides abstractions of HTTP messages and their components and defines a consistent set of interfaces to work with them.
The purpose of PSR-7 is to provide PHP with a set of common interfaces for HTTP messages as described in RFC 7230 and RFC 7231, and URIs as described in RFC 3986 (in the context of HTTP messages).
All HTTP messages consist of the HTTP protocol version being used, headers, and a message body. A Request builds on the message to include the HTTP method used to make the request, and the URI to which the request is made. A Response includes the HTTP status code and reason phrase.
In PHP, HTTP messages are used in two contexts:
- To send an HTTP request, via the ext/curl extension, PHP's native stream layer, etc., and process the received HTTP response. In other words, HTTP messages are used when using PHP as an HTTP client.
- To process an incoming HTTP request to the server, and return an HTTP response to the client making the request. PHP can use HTTP messages when used as a server-side application to fulfil HTTP requests.