- Is kriswallsmith/buzz a good alternative to Guzzle for Laravel HTTP requests?
- Buzz is ideal if you need a lightweight, PSR-7 compliant client without Guzzle’s overhead. It’s perfect for simple requests, scraping, or HTTP/2 server push, but lacks Guzzle’s async support and active development. Laravel’s built-in `Http` facade (Guzzle-based) may suffice for most cases.
- How do I install Buzz in a Laravel project?
- Run `composer require kriswallsmith/buzz` and install a PSR-17 factory like `nyholm/psr7` (`composer require nyholm/psr7`). Buzz requires this dependency to create PSR-7 requests/responses. No Laravel-specific setup is needed unless you build a custom wrapper.
- Which Buzz client should I use for Laravel: FileGetContents, Curl, or MultiCurl?
- Use **Curl** for most cases (balanced performance and features). **FileGetContents** is simplest but blocking; **MultiCurl** is fastest for batch requests or HTTP/2 server push (e.g., asset preloading). Avoid MultiCurl if you don’t need its advanced features.
- Does Buzz support Laravel’s middleware stack (e.g., auth, logging)?
- Yes, Buzz supports middleware via its `Browser` class. You can chain middleware like `BasicAuthMiddleware` or `LoggerMiddleware`, but you’ll need to manually map Laravel’s global middleware (e.g., `Http::withToken()`) to Buzz’s equivalents.
- Is Buzz compatible with Laravel 10+ and PHP 8.1+?
- Yes, Buzz supports PHP 8.1+ and Symfony 8, which aligns with Laravel 10+. It’s feature-complete (since v1.0) with no breaking changes, but long-term maintenance depends on community adoption. Test thoroughly if using legacy code with deprecated methods.
- Can I use Buzz for HTTP/2 server push in Laravel?
- Yes, Buzz’s **MultiCurl** client supports HTTP/2 server push, useful for preloading assets or performance-critical APIs. Enable it by configuring the client with HTTP/2 support, but note this requires PHP’s `curl` extension with HTTP/2 enabled.
- How do I integrate Buzz with Laravel’s Http facade (e.g., replace Guzzle)?
- Buzz doesn’t natively integrate with Laravel’s `Http` facade, but you can create a wrapper service provider or facade (e.g., `Buzz::get($url)`) to mimic Guzzle’s API. Alternatively, use Buzz directly in services/controllers with PSR-17 factories.
- What are the performance trade-offs between Buzz’s clients?
- **FileGetContents** is simplest but blocking and slow for multiple requests. **Curl** is faster with connection pooling and supports middleware. **MultiCurl** is fastest for batch requests (e.g., scraping) but complex to configure. Benchmark your use case.
- Does Buzz support async requests like Symfony’s HttpClient?
- No, Buzz is synchronous-only. For async requests, consider Symfony’s `HttpClient` (uses ReactPHP) or Guzzle’s promises. Buzz’s **MultiCurl** can batch requests concurrently but doesn’t return promises or futures.
- How do I handle cookies or redirects with Buzz in Laravel?
- Buzz’s `Browser` class handles cookies and redirects automatically. For Laravel, store cookies in a session or use middleware to pass them between requests. Example: `$browser->setCookieJar(new CookieJar())` to persist cookies across requests.