Download the PHP package zealphp/mongodb without Composer
On this page you can find all versions of the php package zealphp/mongodb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zealphp/mongodb
More information about zealphp/mongodb
Files in zealphp/mongodb
Package mongodb
Short Description Async MongoDB driver for ZealPHP — Rust extension with PHP OOP library, non-blocking via eventfd + OpenSwoole coroutines
License MIT
Homepage https://github.com/sibidharan/zealphp-mongodb
Informations about the package mongodb
zealphp-mongodb
Async MongoDB driver for PHP — a Rust extension bridging the official mongo-rust-driver into PHP via ext-php-rs, with non-blocking coroutine support through OpenSwoole.
Drop-in replacement for mongodb/mongodb with the same Collection, Database, Client, and BSON APIs.
Performance
C driver parity achieved. 7 of 10 operations match or beat the official C driver (ext-mongodb). Total overhead: +4.1%.
200 iterations, median timing, PHP 8.4.5, MongoDB 6.0, same host:
| Operation | zealphp-mongodb | ext-mongodb (C) | Gap |
|---|---|---|---|
| findOne | 0.442ms | 0.451ms | -1.9% |
| find(50) | 0.550ms | 0.494ms | +11.3% |
| find(1000) | 4.270ms | 3.764ms | +13.4% |
| insertOne | 0.297ms | 0.292ms | +1.6% |
| updateOne | 0.493ms | 0.519ms | -5.0% |
| deleteOne | 0.598ms | 0.610ms | -2.1% |
| countDocuments | 0.883ms | 0.901ms | -2.1% |
| aggregate | 1.415ms | 1.458ms | -2.9% |
| distinct | 0.795ms | 0.820ms | -3.0% |
| findOneAndUpdate | 0.511ms | 0.539ms | -5.1% |
With coroutine parallelism (ZealPHP/OpenSwoole), 4 parallel queries complete in 0.69ms vs 1.7ms sequential on the C driver — 3.4x faster. Under HTTP concurrency (ab -n 500 -c 20), throughput is 3.9x–6.7x higher than Apache + C driver:
| Endpoint | Apache (C driver) | ZealPHP (Rust driver) | Speedup |
|---|---|---|---|
| Landing page (5 DB queries) | 120 req/s · 78ms p50 | 465 req/s · 20ms p50 | 3.9x |
| /features (lightweight) | 254 req/s · 37ms p50 | 1699 req/s · 5ms p50 | 6.7x |
Measured in production on the same container, same MongoDB, same dataset (10k+ users). The landing page parallelizes 5 count queries via Channel(5) + go() coroutines; Apache runs them sequentially.
See docs/case-study-dual-runtime.md for the full analysis.
Features
- Full API parity with the official PHP MongoDB library — Collection (25 methods), Database (15 methods), Client (12 methods)
- Non-blocking async via eventfd + OpenSwoole
Event::add+Channel— zero thread blocking in coroutine mode - Complete BSON type system — ObjectId, UTCDateTime, Regex, Binary, Decimal128, Int64, Timestamp, Javascript, MinKey, MaxKey, Document, PackedArray
- All query options — upsert, returnDocument, projection, sort, limit, skip on both sync and async paths
- Rust performance — backed by the official MongoDB Rust driver with tokio async runtime
- Connection pooling — persistent connections across requests, managed by the Rust extension
- Dual-mode operation — sync (block_on) without OpenSwoole, async (eventfd) with OpenSwoole coroutines
Requirements
- PHP >= 8.1
- Rust toolchain (for building the extension)
- MongoDB server 5.0+
- OpenSwoole (optional, for async coroutine mode)
Installation
Build the Rust extension
Docker
The extension builds automatically in Docker — see the labs-devops Dockerfile for reference:
Install the PHP library
Quick Start
Async Mode (OpenSwoole)
When running inside an OpenSwoole coroutine, all MongoDB operations automatically become non-blocking:
API Reference
Collection Methods
| Method | Description |
|---|---|
findOne($filter, $options) |
Find a single document |
find($filter, $options) |
Find documents (returns Cursor) |
insertOne($document) |
Insert a single document |
insertMany($documents) |
Insert multiple documents |
updateOne($filter, $update, $options) |
Update a single document |
updateMany($filter, $update, $options) |
Update multiple documents |
deleteOne($filter) |
Delete a single document |
deleteMany($filter) |
Delete multiple documents |
replaceOne($filter, $replacement, $options) |
Replace a single document |
countDocuments($filter) |
Count documents matching filter |
estimatedDocumentCount() |
Fast approximate count |
distinct($field, $filter) |
Get distinct values |
aggregate($pipeline) |
Run aggregation pipeline |
findOneAndUpdate($filter, $update, $options) |
Find and update atomically |
findOneAndDelete($filter) |
Find and delete atomically |
findOneAndReplace($filter, $replacement, $options) |
Find and replace atomically |
bulkWrite($operations) |
Execute bulk operations |
createIndex($keys, $options) |
Create an index |
createIndexes($indexes) |
Create multiple indexes |
listIndexes() |
List collection indexes |
dropIndex($name) |
Drop an index |
dropIndexes() |
Drop all indexes |
drop() |
Drop the collection |
rename($newName) |
Rename the collection |
count($filter) |
Alias for countDocuments |
Database Methods
| Method | Description |
|---|---|
command($command) |
Run a database command |
aggregate($pipeline) |
Database-level aggregation |
createCollection($name) |
Create a collection |
dropCollection($name) |
Drop a collection |
drop() |
Drop the database |
listCollections() |
List collections |
listCollectionNames() |
List collection names |
selectCollection($name) |
Get a Collection instance |
selectGridFSBucket() |
Get a GridFS Bucket (stub) |
BSON Types
| Type | Extended JSON |
|---|---|
ObjectId |
{"$oid": "..."} |
UTCDateTime |
{"$date": {"$numberLong": "..."}} |
Regex |
{"$regularExpression": {"pattern": "...", "options": "..."}} |
Binary |
{"$binary": {"base64": "...", "subType": "..."}} |
Decimal128 |
{"$numberDecimal": "..."} |
Int64 |
Native int |
Timestamp |
{"$timestamp": {"t": ..., "i": ...}} |
Javascript |
{"$code": "..."} |
MinKey |
{"$minKey": 1} |
MaxKey |
{"$maxKey": 1} |
Architecture
Development
License
MIT