Generated by GPT-5-mini| PSR-7 | |
|---|---|
| Name | PSR-7 |
| Subject | PHP Standard Recommendation |
| Established | 2015 |
| Scope | HTTP message interfaces for PHP |
| Related | PHP, FIG, HTTP/1.1, HTTP/2 |
PSR-7 PSR-7 is a PHP Standard Recommendation that specifies interfaces for HTTP messages used in request–response message handling. It defines immutable objects for requests, responses, URIs, streams, and uploaded files to enable interoperability across frameworks, libraries, and middleware in the PHP ecosystem. Major PHP projects, middleware libraries, and web frameworks adopted these interfaces to allow components from disparate vendors to compose without tight coupling.
PSR-7 provides a set of interfaces intended for implementation by libraries and frameworks to represent HTTP messages. Influenced by the specifications of Tim Berners-Lee, Roy Fielding, World Wide Web Consortium, Mozilla Foundation, IETF, and the HTTP protocol families HTTP/1.1 and HTTP/2, the specification maps concepts from the Hypertext Transfer Protocol and the RFC 7230 series into PHP contracts. It complements PHP core features from PHP Group and interoperates with ecosystems led by organizations and projects such as Zend Framework, Laravel LLC, Symfony SAS, Drupal Association, WordPress Foundation, Composer (software), and Packagist. The design permits middleware patterns used by projects like Slim framework, Aura Framework, Zend Expressive, Laminas Project, and Mezzio.
PSR-7 defines a minimal set of interfaces representing HTTP messages and message constituents. The central interfaces correspond to concepts found in RFC 7231, RFC 7230, RFC 3986, and IETF HTTP Working Group outputs and include: request, response, stream, URI, headers, and uploaded file abstractions. Implementations must address semantics from specifications authored by contributors affiliated with institutions like MIT, University of Cambridge, University of Oxford, Google LLC, Microsoft Corporation, Facebook, Inc., Amazon.com, Inc., and standards bodies including IETF and W3C. These interfaces enable middleware chains similar to those used by Rack (webserver interface), WSGI, and Java Servlet API, and echo patterns used in Express (software), Django Software Foundation, and Ruby on Rails ecosystems.
Multiple libraries implement the PSR-7 interfaces, allowing reuse across prominent projects and hosting environments. Implementations and adapters were built by vendors and communities associated with Zend Framework, Guzzle, Nyholm, Slim framework, Symfony Project, Laravel LLC, Mezzio, and Laminas Project. Cloud and platform providers like Heroku, Amazon Web Services, Google Cloud Platform, Microsoft Azure, and DigitalOcean host applications using PSR-7–compatible middleware. Tools for testing and debugging that integrate PSR-7 include projects maintained by organizations such as SPL (Standard PHP Library), PHPUnit, Behat, Pest (testing framework), and services from GitHub, Inc., GitLab Inc., and Bitbucket (Atlassian). The interfaces facilitate interoperability with HTTP client ecosystems such as Guzzle (software), cURL, and HTTP servers like NGINX, Apache HTTP Server, and Caddy (web server).
PSR-7 originated within the PHP Framework Interop Group (FIG) as part of efforts to standardize common building blocks across PHP projects. The movement drew attention from maintainers involved with Zend Framework, Symfony SAS, Laravel LLC, Drupal Association, and independent library authors. Discussions occurred in venues frequented by contributors affiliated with GitHub, Inc., Composer (software), and community forums connected to Stack Overflow, Reddit (website), and IRC channels tied to various projects. The standardization process paralleled other language-community interface efforts such as PSR-0, PSR-4, and interface patterns in Java Community Process and PEP (Python Enhancement Proposal), with implementations and community endorsement following original publication.
PSR-7 emphasizes immutability, explicit abstraction of HTTP message parts, and decoupling of application logic from server APIs and SAPI environments like FastCGI, FPM, and Apache HTTP Server modules. The immutability principle mirrors functional programming influences associated with researchers and institutions like Edsger W. Dijkstra, Tony Hoare, MIT, and Stanford University in software design history. The interfaces provide stream-based payload handling compatible with PHP stream wrappers and binary-safe I/O stacks developed in the broader ecosystem used by projects such as Monolog, PSR-3, PSR-6, and PSR-11. PSR-7 supports middleware composition patterns adopted from middleware ecosystems including Rack (webserver interface), WSGI, and Java Servlet API to enable reusable components like routers, authentication modules, and error handlers authored by communities tied to Symfony Project, Laravel LLC, and Zend Framework.
PSR-7 faced criticism and practical challenges regarding complexity, immutability ergonomics, and adapter friction with existing codebases and server APIs. Critics from community figures and projects such as WordPress Foundation, Drupal Association, and certain legacy PHP applications pointed to migration cost and cognitive overhead. Compatibility issues arose when integrating PSR-7 with legacy SAPI-driven code, extensions maintained by vendors like PHPMailer, PECL, or hosting stacks used by cPanel, LLC and Plesk International GmbH. Debates in the community referenced interoperability trade-offs similar to those seen in transitions involving Java EE, AngularJS to Angular, and Python 2 to Python 3. Subsequent tooling, adapters, and bridge libraries from contributors associated with Symfony Project, Laminas Project, Guzzle, and other ecosystems reduced friction but did not eliminate debates over API ergonomics and learning curves.