wwaayyaa/mysql-timeout
Composer 安装命令:
composer require wwaayyaa/mysql-timeout
包简介
Customizing the timeout for a database query
README 文档
README
Customizing the timeout for a database query
Install
composer.json
{ "require": { "wwaayyaa/mysql-timeout": "dev-master" } }
$ composer install
Example
php code
$conf = Conf::$db1; print_r($conf); $d = new MysqlTimeout($conf); echo "now:".time()."\n"; $r = $d->query('select sleep(2) as `sleep`,2 as `sec`;'); print_r($r); echo "sleep 2s,now:".time()."\n"; try{ $r = $d->query('select sleep(5) as `sleep`,5 as `sec`;',3); }catch(Exception $e){ echo sprintf("error message:%s ,error code : %d \n",$e->getMessage(),$e->getCode()); } echo "sleep 5s but timeout is 3s,so throw a error.now:".time()."\n"; $d = new MysqlTimeout($conf);//must new a MysqlTimeout. because $r = $d->query('select sleep(5) as `sleep`,5 as `sec`;',6); print_r($r); echo "sleep 5s success,because timeout is 6s. now:".time()."\n"; //Other methods $r = $d->update("update dtk_zhibo_chat_log set addtime=now() where id = 6 or id = 17;"); echo sprintf("success rows:%d \n",$r); $r = $d->insert("insert into dtk_zhibo_chat_log (zhiboId,content) values (1292,'test');"); echo sprintf("primary id:%d \n",$r);
result
Array ( [host] => 127.0.0.1 [port] => 3306 [user] => root [password] => root [dbname] => test [charset] => utf8 ) now:1475056910 Array ( [0] => Array ( [sleep] => 0 [sec] => 2 ) ) sleep 2s,now:1475056912 error message:timeout ,error code : 922922 sleep 5s but timeout is 3s,so throw a error.now:1475056915 Array ( [0] => Array ( [sleep] => 0 [sec] => 5 ) ) sleep 5s success,because timeout is 6s. now:1475056920 success rows:2 primary id:1036
Method
/** * @return mixed query data */ public function query($sql, $timeout = 3); /** * @return int rows count */ public function update($sql, $timeout = 3); /** * @return int data primary id */ public function insert($sql, $timeout = 3); /** * @return int rows count */ public function delete($sql, $timeout = 3);
Args
config
- host | must '127.0.0.1'
- port | non-must '3306'
- user | must 'root'
- password | must 'root'
- dbname | must 'text'
- charset | must 'utf8'
- timeout | non-must 3
timeout (defalut : 3)
- The MsyqlTimeout inspection cycle is
0.05seconds, - so the minimum value of the $timeout parameter is 0.05,
- the maximum value depends on the PHP.ini
max_execution_timeand MySQLtimeout settings.
Exception
errorcode
If the query timeout, MysqlTimeout will throw an exception, the exception number
922922
wwaayyaa/mysql-timeout 适用场景与选型建议
wwaayyaa/mysql-timeout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mysql」 「query」 「timeout」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wwaayyaa/mysql-timeout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wwaayyaa/mysql-timeout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wwaayyaa/mysql-timeout 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Emulated timeouts for synchronous operations.
Users are warned about expiring session.
Query filtering in your frontend
Anax Database Active Record module for model classes.
Database/ORM-agnostic query construction helper
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-25