- Can I use clue/buzz-react in a Laravel controller for API calls?
- No, buzz-react is async and non-blocking, which conflicts with Laravel’s synchronous request lifecycle. Use it only for background tasks via Laravel Queues or CLI scripts. For controllers, stick with Guzzle or Symfony’s HTTP client.
- How do I install buzz-react in a Laravel project?
- Run `composer require clue/buzz-react`. Ensure your project uses ReactPHP (e.g., `react/event-loop`). Note: This package is deprecated, so test thoroughly for compatibility with your PHP/ReactPHP versions.
- Does buzz-react support Laravel’s HTTP client middleware (e.g., retries, auth)?
- Yes, buzz-react is PSR-7 compliant, so middleware like Symfony’s HttpClient or Guzzle middleware can be adapted. However, async middleware execution may require custom handling for shared state like cookies or tokens.
- Will buzz-react work with Laravel 10 and PHP 8.2?
- Unlikely without modifications. The last release was in 2020 and may break on PHP 8.1+. Test thoroughly or consider forking the package. Alternatives like Amp or Symfony’s HttpClient are actively maintained.
- How do I handle timeouts and retries with buzz-react?
- Use ReactPHP’s built-in timeout features or wrap requests in middleware. For retries, implement a custom retry loop with exponential backoff. Example: `$client->request($request)->then(...)->otherwise(function ($error) { retry(); })`.
- Can I stream responses from buzz-react in Laravel?
- Yes, buzz-react supports streaming responses via ReactPHP’s `onData` and `onEnd` callbacks. For Laravel, stream the response directly to a file or output buffer, but avoid mixing with synchronous Blade templates.
- What’s the best way to integrate buzz-react with Laravel Queues?
- Create a custom queue worker that initializes ReactPHP’s event loop. Dispatch async tasks via `AsyncHttpTask::dispatch()` and process them in a React-powered worker. Example: `php artisan queue:work --queue=async-http --daemon`.
- Are there alternatives to buzz-react for async HTTP in Laravel?
- Yes. For Laravel, consider Symfony’s HttpClient (async via ReactPHP), Amp’s HTTP client, or Guzzle’s async plugins. If you need Swoole integration, use Swoole’s coroutines or RoadRunner’s async workers.
- How do I test buzz-react in PHPUnit?
- Mock ReactPHP’s event loop or use async-aware testing tools like `php-react/promise`. Example: `$this->expectException(TimeoutException::class);` for timeout tests. Avoid relying on global state in async tests.
- What are the production risks of using buzz-react in Laravel?
- Key risks include: debugging async stack traces, lack of observability (no built-in metrics), and potential conflicts with Laravel’s synchronous components. Monitor for race conditions in shared state (e.g., auth tokens) and plan for eventual migration.