Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for Discord Gateway zstd-stream transport compression (preferring zstd when available, with fallback to existing zlib-stream) and updates dependency suggestions accordingly.
Changes:
- Add optional
ext-zstdComposer suggestion. - Initialize a zstd decompression context when
ext-zstdis available and requestzstd-streamcompression. - Decompress binary WebSocket payloads using zstd when selected, otherwise keep existing zlib-stream behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Discord/Discord.php | Adds zstd decompression context setup, selects zstd-stream in gateway params when available, and handles zstd-decompressed binary payloads. |
| composer.json | Suggests ext-zstd for optional Zstandard compression support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ($this->useTransportCompression) { | ||
| if ($this->zlibDecompressor = inflate_init(ZLIB_ENCODING_DEFLATE)) { | ||
| // Prefer zstd-stream if available (better compression), fallback to zlib-stream | ||
| if (extension_loaded('zstd') && ($this->zstdDecompressor = uncompress_init())) { | ||
| $params['compress'] = 'zstd-stream'; | ||
| $this->logger->debug('using zstd-stream compression'); | ||
| } elseif ($this->zlibDecompressor = inflate_init(ZLIB_ENCODING_DEFLATE)) { | ||
| $params['compress'] = 'zlib-stream'; | ||
| $this->logger->debug('using zlib-stream compression'); |
There was a problem hiding this comment.
New zstd-stream selection and decompression behavior isn’t covered by automated tests. Consider adding a unit test that verifies (a) buildParams prefers zstd-stream when available and falls back to zlib-stream otherwise, and (b) handleWsMessage routes binary payloads through the selected decompressor (you may need to wrap the extension checks/calls to make this testable without ext-zstd in CI).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
https://discord.com/developers/docs/events/gateway#zstdstream
https://github.com/kjdev/php-ext-zstd
https://phpext.phptools.online/extension/zstd-334
This pull request adds support for Zstandard (zstd) compression in addition to the existing zlib compression for WebSocket payloads in the
Discordclient. If theext-zstdextension is available, the client will now prefer zstd-stream compression, falling back to zlib-stream if not. The changes include dependency updates, new decompression logic, and improved logging for compression handling.Compression support improvements:
ext-zstdas a suggested dependency incomposer.jsonfor Zstandard compression support.Discordclient to initialize and use a Zstd decompression context (ZstdContext) if the extension is available, falling back to zlib decompression otherwise. [1] [2] [3]WebSocket message handling:
Logging and diagnostics: