antevenio/pdo-mysql-select-iterator
Composer 安装命令:
composer require antevenio/pdo-mysql-select-iterator
包简介
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses
README 文档
README
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses.
What is this thing
So, you want to iterate through millions of table rows coming as a result of some MySQL select query because you want to do your thingie with them, but alas!, your lovely database admin doesn't like queries that stay for too long running in his server, or even worse, the server itself isn't able to hold them!. What do we do?, we do issue several queries that would fetch smaller blocks of rows in place.
This is an just a PHP iterator based on this concept. Upon receiving a SELECT query and a PDO database connection, an iterator is built so you can seamlessly traverse results without having to worry about anything else.
Install
To add as a dependency using composer:
composer require antevenio/pdo-mysql-select-iterator
Usage example
<?php $pdo = new PDO('mysql:host=localhost;dbname=kidsshouting', 'myuser', 'mypass'); $iterator = (new \PdoMysqlSelectIterator\Factory()) ->create($pdo, "select a,b from tbl order by a", 1000); // Get a total row count from the query if needed $total = count($iterator); foreach ($iterator as $item) { // Do your stuff with $item }
Notes
The factory will throw a InvalidQueryException on non "select" queries.
The factory will only return a LimitIterator when:
- The blockSize is > 0
- The query has an "order by" clause
- The query is not using any "rand()" functions
If any of the previous conditions is NOT met, the factory will return a non limit based iterator called "NativePDOIterator".
To ensure consistency among results, you might want to get the whole iteration and count inside a database transaction. The most suitable isolation level would be REPEATABLE-READ:
antevenio/pdo-mysql-select-iterator 适用场景与选型建议
antevenio/pdo-mysql-select-iterator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.92k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「iterator」 「mysql」 「pdo」 「select」 「limit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 antevenio/pdo-mysql-select-iterator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 antevenio/pdo-mysql-select-iterator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 antevenio/pdo-mysql-select-iterator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
collection php library
Iteration tools for PHP
Sequential way to run Symfony Processes in parallel
Extends XMLReader PHP class, for simple SAX-reading and XPath queries of huge XML files.
Trait providing methods implementing the Iterator interface.
统计信息
- 总下载量: 20.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-23