Skip to content

Conversation

@thekid
Copy link
Member

@thekid thekid commented Jul 26, 2025

Implements feature suggested in #61

Supported compressors

Negotiation

To enable compression, add the preferred compressors to the connection URI as follows

mongodb://username:password@host/test?compressors=zstd,zlib[&zlibCompressionLevel=6][&zstdCompressionLevel=3]

The server will answer with the compressors it supports, which in turn will be matched against the list of PHP extensions loaded. The client will align its preference with the order in which the server returns the compressors.

The compression levels, if not specified, default to -1, which will in turn use the defaults for the given compressor.

Debugging

use com\mongodb\MongoConnection;
use util\cmd\Console;

$c= new MongoConnection($dsn);
$c->connect();

// Compression: com.mongodb.io.Compression@[
//   com.mongodb.io.Zlib(id: 2, level: -1)
//   com.mongodb.io.Zstd(id: 3, level: -1)
// ]
Console::writeLine('Compression: ', current($c->protocol()->connections())->compression);

@thekid
Copy link
Member Author

thekid commented Jul 27, 2025

Snappy might be doable by porting https://github.com/zhipeng-jia/snappyjs

@thekid thekid added the enhancement New feature or request label Jul 27, 2025
@thekid thekid merged commit 0e300f8 into master Jul 27, 2025
12 checks passed
@thekid thekid deleted the feature/compression branch July 27, 2025 10:25
@thekid
Copy link
Member Author

thekid commented Jul 27, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants