alcaeus/mongo-php-adapter
Composer 安装命令:
composer require alcaeus/mongo-php-adapter
包简介
Adapter to provide ext-mongo interface on top of mongo-php-library
README 文档
README
The Mongo PHP Adapter is a userland library designed to act as an adapter
between applications relying on ext-mongo and the new driver (ext-mongodb).
It provides the API of ext-mongo built on top of mongo-php-library, thus being compatible with PHP 7.
Goal
This library aims to provide a compatibility layer for applications that rely on
libraries using ext-mongo, e.g.
Doctrine MongoDB ODM, but want to
migrate to PHP 7 on which ext-mongo will not run.
You should not be using this library if you do not rely on a library using
ext-mongo. If you are starting a new project, please check out
mongodb/mongodb.
Installation
This library requires you to have the mongodb extension installed, and it
conflicts with the legacy mongo extension.
The preferred method of installing this library is with Composer by running the following from your project root:
$ composer config "platform.ext-mongo" "1.6.16" && composer require alcaeus/mongo-php-adapter
The above command first marks the mongo extension as installed, then requires
this adapter. This is to work around a bug in composer, see
composer/composer#5030.
Known issues
Return values and exceptions
Some methods may not throw exceptions with the same exception messages as their
counterparts in ext-mongo. Do not rely on exception messages being the same.
Methods that return a result array containing a connectionId field will always
return 0 as connection ID.
Errors
All errors and warnings triggered by ext-mongo are triggered as E_USER_WARNING
and E_USER_ERROR because trigger_error doesn't accept the E_WARNING and
E_USER codes. If you rely on these error codes in your error handling routines,
please update your code accordingly.
Serialization of objects
Serialization of any Mongo* objects (e.g. MongoGridFSFile, MongoCursor, etc.) will not work properly. The objects can be serialized but are not usable after unserializing them.
Mongo
- The Mongo class is deprecated and was not implemented in this library. If you are still using it please update your code to use the new classes.
MongoLog
- The MongoLog class does not log anything because the underlying driver does not offer a method to retrieve this data.
MongoClient
- The connect and close methods are not implemented because the underlying driver connects lazily and does not offer methods for connecting disconnecting.
- The getConnections method is not implemented because the underlying driver does not offer a method to retrieve this data.
- The killCursor method is not yet implemented.
MongoDB
- The authenticate method is not supported. To connect to a database with authentication, please supply the credentials using the connection string.
- The
$cmdcollection cannot be used due to an issue in the underlying driver. To run commands, use the command method instead of querying the virtual$cmdcollection.
MongoCollection
- The insert, batchInsert, and save methods take the first argument by reference. While the original API does not explicitely specify by-reference arguments it does add an ID field to the objects and documents given.
- The parallelCollectionScan method is not yet implemented.
MongoCursor
- The info method does not
reliably fill all fields in the cursor information. This includes the
numReturnedandserverkeys once the cursor has started iterating. ThenumReturnedfield will always show the same value as theatfield. Theserverfield is lacking authentication information. - The setFlag method is not yet implemented.
- The timeout method will not change any query options. Client-side timeouts are no longer supported by the new driver. Use the maxTimeMS setting as a replacement.
MongoCommandCursor
- The createFromDocument method is not yet implemented.
- The info method does not
reliably fill all fields in the cursor information. This includes the
at,numReturned,firstBatchAtandfirstBatchNumReturnedfields. TheatandnumReturnedfields always return 0 for compatibility to MongoCursor. ThefirstBatchAtandfirstBatchNumReturnedfields will contain the same value, which is the internal position of the iterator.
Development
If you are working on patches to this driver, you can run the unit tests by following these steps from the root of the repo directory:
$ composer install
$ vendor/phpunit/phpunit/phpunit --verbose
It assumes that the the localhost is running a mongod server. Here is a sample command to start mongod for these tests:
$ mongod --smallfiles --fork --logpath /var/log/mongod.log --setParameter enableTestCommands=1
The tests also assume PHP 5.6+ and the ext-mongodb extension being available.
alcaeus/mongo-php-adapter 适用场景与选型建议
alcaeus/mongo-php-adapter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.56M 次下载、GitHub Stars 达 464, 最近一次更新时间为 2015 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「mongodb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alcaeus/mongo-php-adapter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alcaeus/mongo-php-adapter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alcaeus/mongo-php-adapter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Generates Symfony2 documents, forms and CRUD
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
A package to allow laravel/passport use with mongodb/laravel-mongodb
统计信息
- 总下载量: 12.56M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 471
- 点击次数: 21
- 依赖项目数: 94
- 推荐数: 54
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-30