discord-php/http
Async PHP HTTP client for the Discord REST API (PHP 7.4+). Works with an event loop (e.g., React) and PSR-3 logging. Provides get/post/put/patch/delete plus queueRequest, returns decoded JSON promises, and includes Endpoint constants with bind() for rate-limit buckets.
Endpoint::SKU_SUBSCRIPTIONS, Endpoint::POLL_*) reduce boilerplate by 60–80% for Discord use cases, but generic HTTP clients (Guzzle) may suffice for non-Discord APIs.Endpoint::bind() is critical for high-volume bots (e.g., moderation tools) but adds complexity for low-traffic apps.// Octane Worker
$http = new Http('BotToken', $loop, $logger);
$http->setDriver(new React($loop));
$loop->run();
react/http, nyholm/psr7), adding ~10MB to deployment size.Http in a Laravel service).Endpoint::bind() calls can trigger Discord API bans if bucketing is ignored.Endpoint::CHANNEL_POLL_*).Async Readiness:
Architecture Alignment:
Rate-Limit Sensitivity:
Endpoint::bind()) is mandatory.Laravel Integration Depth:
Long-Term Maintenance:
Endpoint::SOUNDBOARD_* for new features)?Alternatives Evaluated:
| Component | Fit Level | Notes |
|---|---|---|
| Laravel Octane | High | Native async support with Swoole/Preact. Offload Discord API to workers. |
| Laravel Queues | Medium | Requires custom job wrappers to bridge async Http with sync queues. |
| Traditional MVC | Low | Async design clashes with sync controllers. Needs Promises adapters. |
| ReactPHP | High | Core dependency for async HTTP. Team must adopt ReactPHP’s event loop. |
| PSR-15/PSR-17 | High | Required for HTTP middleware/servers (e.g., react/http). |
| Monolog | High | Recommended for logging. Easy to integrate. |
| Guzzle | Low | Alternative for sync workloads. Lacks Discord-specific optimizations. |
Assess Async Needs:
Architecture Changes:
// app/Jobs/ProcessDiscordWebhook.php
public function handle() {
$http = new Http(config('discord.token'), $loop, $logger);
$http->setDriver(new React($loop));
$http->post('webhooks/...')->done(...);
$loop->run();
}
Http in a Promise → Sync adapter (e.g., await helpers).Endpoint Adoption:
Endpoint::CHANNEL_MESSAGE).// Before
$http->get('channels/123/messages/456');
// After
$endpoint = Endpoint::bind(Endpoint::CHANNEL_MESSAGE, '123', '456');
$http->get($endpoint);
Rate-Limit Strategy:
Endpoint::bind() for all parameterized endpoints.DiscordRateLimiter).Logging and Observability:
$logger = (new Logger('discord'))->pushHandler(new StreamHandler(storage_path('logs/discord.log')));
Phase 1: Async Infrastructure (2–4 weeks):
Phase 2: Core Integration (1–2 weeks):
discord-php/http.Endpoint::bind() for rate-limit compliance.Phase 3: Advanced Features (1–2 weeks):
Http in a Laravel service for dependency injection.Phase 4: Testing and Optimization (2–3 weeks):
How can I help you explore Laravel packages today?