- Can I use DiscordPHP-Http in a traditional Laravel MVC app without async workers?
- No, this package is async-first and requires ReactPHP or an event loop. For synchronous Laravel apps, you’d need to wrap async responses in Promises or use Guzzle instead. It’s best suited for Laravel Octane (Swoole/Preact) or queue-based architectures.
- How do I integrate this with Laravel Octane for Discord bot commands?
- In Octane, initialize the HTTP client in a worker class using Swoole/Preact’s event loop. Offload Discord API calls to workers to avoid blocking sync routes. Example: `$http = new Http('token', $loop, $logger); $http->setDriver(new React($loop));` in your worker’s `handle()` method.
- What Laravel versions support DiscordPHP-Http?
- The package works with PHP 7.4+ and Laravel 8+ (for Octane/Swoole) or Laravel 9+ (Preact). It’s not tied to Laravel’s HTTP layer but requires async-compatible Laravel setups. Traditional MVC apps need custom async-to-sync bridges.
- How do I handle rate limits with Endpoint::bind()?
- Use `Endpoint::bind()` to group requests by Discord’s rate-limit buckets (e.g., `Endpoint::bind(Endpoint::CHANNEL_MESSAGE, '123', '456')`). This auto-manages buckets like `/channels/:channel` or `/guilds/:guild`. Ignoring it risks API bans for high-traffic bots.
- Is there a way to use this without ReactPHP?
- No, ReactPHP is a core dependency for the event loop. Alternatives like Guzzle are synchronous and lack Discord-specific optimizations. If you can’t use ReactPHP, consider wrapping Guzzle in a queue worker or using a different async library like Amp.
- Can I test DiscordPHP-Http in Laravel’s PHPUnit?
- Yes, but testing async code requires mocking the event loop. Use libraries like `react/promise` or `phpunit/react` to test Promises. Example: `$promise = $http->get('endpoint'); $this->assertTrue($promise->isPending());` in your tests.
- What’s the performance impact of using this vs. Guzzle?
- DiscordPHP-Http is faster for high-volume Discord APIs due to pre-built endpoints and rate-limit bucketing, reducing boilerplate. Guzzle adds ~10–15ms per request for manual rate-limit logic, while this package optimizes for Discord’s API structure. Benchmark with your workload.
- How do I log errors in production?
- Use PSR-3 logging (e.g., Monolog) with the `$logger` parameter in `Http()`. Configure Monolog’s handlers (e.g., `StreamHandler`, `SyslogHandler`) to log errors to your preferred destination. Errors in Promises are caught via `.fail()` callbacks.
- Will this work with Laravel Queues for background Discord API calls?
- Indirectly—you’d need to wrap the async HTTP client in a Laravel Job. The Job’s `handle()` method would initialize the event loop and process requests. Example: `new DiscordApiJob($http, $endpoint)->onQueue('discord');` with a custom queue worker.
- Are there alternatives for Laravel Discord bots with less async complexity?
- Yes: **Guzzle** (sync, no ReactPHP) or **Amp** (async, but requires learning Amp’s event loop). DiscordPHP-Http’s advantage is Discord-specific endpoints and rate-limit buckets, but Guzzle is simpler for teams without async experience. Weigh your need for Discord optimizations vs. ease of use.