guzzlehttp/psr7
Full PSR-7 message implementation with rich stream support: multiple stream types and decorators (append, buffer, caching, etc.), plus helpers like query-string parsing. Installed via Composer and maintained with v2 for PHP 7.2.5+.
AppendStream, LimitStream, CachingStream), which aligns with Laravel’s event-driven and streaming use cases (e.g., file uploads, chunked responses, async processing).Query::parse, Utils::hash, Message::toString) reduce boilerplate in API clients, webhooks, or message transformation logic.UPGRADING.md.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| PSR-7 Adoption | Some legacy Laravel codebases may not use PSR-7 explicitly. | Audit dependencies; enforce PSR-7 via guzzlehttp/psr7 and symfony/http-foundation. |
| Stream Performance | Decorators (e.g., CachingStream) add memory overhead for large payloads. |
Use sparingly; prefer LimitStream for chunking over CachingStream for caching. |
| PHP Version Gaps | v1.x supports PHP 5.4–8.1; v2.x drops PHP <7.2.5. | Enforce PHP 7.4+ in composer.json for new projects. |
| Testing Complexity | Stream decorators require mocking for unit tests. | Use GuzzleHttp\Psr7\Utils::streamFor() for test doubles. |
Symfony\Component\HttpFoundation\StreamedResponse)?DroppingStream for rate-limiting)?^2.0 (latest) or ~1.8 (LTS) for stability?Illuminate\Http\StreamedResponse with PSR-7 streams?| Laravel Component | Integration Strategy |
|---|---|
| Guzzle HTTP Client | Native Fit: Already uses guzzlehttp/psr7 as a dependency. No changes needed. |
| Symfony HTTP | Bridge: Use symfony/http-foundation alongside guzzlehttp/psr7 for interop. |
| File Uploads | Stream Decorators: AppendStream for multipart uploads, LimitStream for chunking. |
| WebSockets | PumpStream: For async data generation (e.g., SSE, WebSocket payloads). |
| Middleware | Custom Decorators: Extend StreamDecoratorTrait for request/response hooks. |
| Testing | Mock Streams: Use Utils::streamFor() in PHPUnit for HTTP message tests. |
fopen, Symfony\StreamedResponse).guzzlehttp/psr7 to composer.json (no code changes).LimitStream for file uploads).FnStream).Symfony\Component\HttpFoundation\StreamedResponse in favor of PSR-7.StreamWrapper for PHP stream resource interop.| Scenario | Compatibility Notes |
|---|---|
| Laravel 9/10 | Full compatibility with guzzlehttp/psr7:^2.0. |
| Lumen | Works identically to Laravel; no additional config needed. |
| Legacy PHP (5.6–7.1) | Requires guzzlehttp/psr7:^1.8 (EOL risk). |
| Symfony Components | symfony/http-foundation can wrap PSR-7 streams via StreamWrapper. |
| Custom Packages | Check for psr/http-message interface usage; no breaking changes expected. |
guzzlehttp/psr7 to composer.json → Run composer update.GuzzleHttp\Client to use PSR-7 streams (if not already).file_get_contents() with Utils::copyToString() for large files.CachingStream for retry logic in failed uploads.LoggingStream for debugging).Illuminate\Http\Client\PendingRequest to support PSR-7 streams.CachingStream + LimitStream) can be tricky.composer.json.guzzlehttp/psr7's built-in CI checks.UPGRADING.md covers v1.x → v2.x migration.CachingStream buffer data; monitor memory usage in high-load scenarios.LimitStream and PumpStream optimize chunked transfers (e.g., S3 multipart uploads).NoSeekStream) work well in queue workers.Symfony\Component\HttpFoundation\StreamedResponse for Laravel-specific use cases.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Stream Corruption | Partial data reads/writes. | Use Utils::hash() to validate stream integrity. |
| Memory Leaks | CachingStream buffers unbounded. |
Set maxMemory in CachingStream; fall back |
How can I help you explore Laravel packages today?