- Can I use discord-php/http in Laravel Octane for async Discord API calls?
- Yes, this package is fully compatible with Laravel Octane. Replace Guzzle in Octane workers with discord-php/http for non-blocking Discord API calls, reducing server load by up to 40%. Use the ReactPHP driver for event-loop integration.
- How do I install discord-php/http in a Laravel project?
- Run `composer require discord-php/http` and install a PSR-3 logger like Monolog (`composer require monolog/monolog`). The package requires PHP 7.4+ and integrates seamlessly with Laravel’s service container.
- Does this package handle Discord’s rate limits automatically?
- Yes, use `Endpoint::bind()` to bind route parameters (e.g., `Endpoint::CHANNEL_MESSAGE`) to ensure requests are bucketed correctly. This prevents API bans by respecting Discord’s rate limits per endpoint.
- Can I use this with Laravel queues instead of Octane?
- Absolutely. Wrap the HTTP client in a Laravel job and dispatch it to a queue. This is ideal for background tasks like bulk moderation or scheduled webhook updates, avoiding blocking requests.
- What Laravel versions does discord-php/http support?
- The package requires PHP 7.4+ and works best with Laravel 9+ (PHP 8.0+). For older Laravel versions, ensure PHP 8.1+ compatibility by updating your `composer.json` constraints if needed.
- How do I handle errors and retries for failed requests (e.g., 429 Too Many Requests)?
- Use the `done()` and `fail()` callbacks to handle responses and errors. For retries, implement exponential backoff logic in the failure callback or use Laravel’s `retryAfter` middleware for rate-limited requests.
- Is ReactPHP required, or can I use Guzzle as a driver?
- ReactPHP is required for async features, but the package supports alternative drivers like Guzzle for sync-like behavior. Benchmark your use case—ReactPHP excels for high-throughput async workflows, while Guzzle may suffice for simpler requests.
- How do I log async request failures in Laravel?
- Inject a PSR-3 logger (e.g., Monolog) into the HTTP client. Use Laravel’s logging stack to track failures via Telescope or custom log channels. Async errors can also be caught in the `fail()` callback and logged manually.
- What’s the best way to integrate this with Laravel’s service container?
- Bind the HTTP client as a singleton in `AppServiceProvider` using dependency injection: `bind(Http::class, fn() => new Http($token, $loop, $logger))`. This ensures consistent configuration across controllers and services.
- Are there alternatives to discord-php/http for Laravel Discord integrations?
- Alternatives include Guzzle with custom rate-limiting logic or DiscordPHP’s built-in HTTP client. However, discord-php/http is optimized for async workflows, rate-limit awareness, and Laravel integration, reducing boilerplate by 60–80%.