- How do I install discord-php/http in a Laravel application?
- Install it with Composer using composer require discord-php/http, then add a PSR-3-compatible logger such as Monolog. The package requires PHP 7.4 or newer and a ReactPHP event loop for the React driver. Laravel does not auto-register a service provider, so you typically instantiate Discord.Http.Http manually or bind it in a custom service provider or container binding.
- Does discord-php/http work with Laravel Octane?
- Yes, it is a high-fit option for Laravel Octane because the client is async-first and designed around a ReactPHP event loop. You can initialize the Http client and React driver in a long-lived worker and offload Discord REST calls to async workers. Be careful with worker state and blocking calls that can stall the event loop.
- Can I use discord-php/http in a traditional synchronous Laravel controller?
- Not directly, because discord-php/http returns promises and is built for asynchronous ReactPHP event-loop execution. Traditional Laravel MVC controllers are synchronous, so you would need Promise-to-sync adapters or custom middleware to bridge responses. The cleaner approach is to move Discord API work into Octane workers, queue jobs, or a dedicated async service.
- How does discord-php/http handle Discord API rate limits?
- It supports rate-limit bucket organization, especially when you use Endpoint.bind to fill endpoint parameters correctly. Binding requests to the right endpoint URL helps the client sort calls into Discord's buckets and avoid unnecessary 429 responses. For high-volume bots or moderation tools, bucket-aware routing is critical because ignoring it can trigger Discord API rate limits or bans.
- What are the requirements for discord-php/http and does it include a Laravel service provider?
- The package requires PHP 7.4 or newer and a PSR-3-compliant logger such as Monolog, which you pass into the Http client to capture request and error context. It also depends on a ReactPHP event loop and the React driver for async HTTP calls. It is framework-agnostic and does not ship a native Laravel service provider or facade, so Laravel integration is manual or via your own container binding.
- How do I bind endpoint parameters with Endpoint::bind in discord-php/http?
- Use Endpoint::bind with an endpoint constant and the parameter values in order, for example Endpoint::bind(Endpoint::CHANNEL_MESSAGE, 'channel_id', 'message_id'). This returns a resolved URL such as channels/channel_id/messages/message_id. The documentation recommends binding parameterized endpoints this way so requests are sorted into the correct rate-limit buckets.
- Is discord-php/http a good alternative to Guzzle for Discord API calls?
- Yes, if you are building an async Discord bot or event-driven integration that benefits from pre-built endpoints and rate-limit bucket awareness. Guzzle is simpler for generic synchronous HTTP and may be enough for low-volume or non-Discord APIs, but it requires you to implement Discord-specific rate-limit logic yourself. The tradeoff is that discord-php/http adds ReactPHP async complexity and dependency overhead.
- How do I test discord-php/http in a Laravel application?
- There are no built-in Laravel testing helpers, so isolate the Http client behind your own service or interface and inject a test double where possible. Test endpoint binding and promise callbacks separately, including success and error handlers, and avoid hitting the real Discord API in unit tests. If you use the React driver, keep the event loop under test control and assert the decoded response objects your code expects.
- Can I use discord-php/http with Laravel queues?
- Yes, but it is a medium fit because the client is async and Laravel queues are synchronous job workers. You will usually need custom job wrappers that bridge the promise-based Http client with queue execution and handle the event loop correctly. This is a good way to offload Discord API calls from web requests without making your controllers async.
- Is discord-php/http maintained for Discord API changes?
- The package is MIT licensed and exposes Discord endpoints as constants, but Discord API changes may require manual updates to those endpoint definitions when routes or features change. You should monitor Discord's API changelog and keep the package and endpoint constants current in production. Without updates, stale endpoints can break bot functionality even if the HTTP client itself is stable.