gonzie/pdoload
最新稳定版本:v0.3.2
Composer 安装命令:
composer require gonzie/pdoload
包简介
Small PDO wrapper to provide read/write split and load balancing in one line of code.
README 文档
README
PDOLoad
PDOLoad is a small PDO wrapper/abstraction layer to provide read/write endpoints and load balancing capabilities in one line of code. Load balancing is usually include within most major PHP Frameworks however when working with large legacy projects it's hard to come by.
Main Features
- Add multiple read and write endpoints.
- One line implementation. No need to rewrite your PDO queries.
- Transaction aware. Any reads while a transaction is active will be performed on the write connection.
Getting started
- PHP >= 7.0 is required
- Install PDOLoad using composer (recommmended) or manually
- Configure your connections and you're ready to go!
Installing with Composer
composer require gonzie/pdoload
How to use
PDOLoad gives you as much choice as possible with little to no modification required. A normal PDO connection would be set like:
$dbh = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8mb4', 'username', 'password');
(most basic set up)
To use a minimalistic version of PDOLoad you would amend the code as follows:
$dbh = new Gonzie\PDOLoad\PDOLoad('mysql:host=localhost;dbname=testdb;charset=utf8mb4', 'username', 'password');
Alternatively, to use PDOLoad to it's full abilities, and for what it was actually made for, you can set up by passing an array with settings.
<?php $settings = [ 'driver' => 'mysql', 'reader' => [ [ 'host' => 'mysuperduperdbreader_1.com', 'dbname' => 'test', 'user' => 'gonzie', 'password' => 'password', 'port' => '3306' 'charset' => 'utf8mb4', ], [ 'host' => 'mysuperduperdbreader_2.com', 'dbname' => 'test', 'user' => 'gonzie', 'password' => 'password', 'charset' => 'utf8mb4', ], ], 'writer' => [ [ 'host' => 'mysuperduperdbwriter_1.com', 'dbname' => 'test', 'user' => 'gonzie', 'password' => 'password', 'charset' => 'utf8mb4', ], ], 'balancer' => 'round-robin', ]; $dbh = new Gonzie\PDOLoad\PDOLoad($settings);
Easy right? Here's a breakdown of the settings array:
| Field | Type | Description |
|---|---|---|
| driver | string | Optional, default is mysql. Available options: pdo_mysql, drizzle_pdo_mysql, mysqli, pdo_sqlite, pdo_pgsql, pdo_oci, pdo_sqlsrv, sqlsrv, oci8, sqlanywhere |
| reader | array[connection] | Required. Array of connection arrays. |
| writer | array[connection] | Required. Array of connection arrays. |
| balancer | string | Optional, default is . Available options: round-robin - go from top to bottom of connection's array, fixed - PDOLoad will pick a connection at random and stick to it, random - each query will pick a random connection. |
| overwrite_allowed | string | Optional, default is false. Some driver options require additional options other than the ones in the connection array, set this value to true if you need to add custom options to the array otherwise they won't be allowed. |
Connection array
Other options can be added to your liking as long as overwrite_allowed is set to true.
| Field | Type | Description |
|---|---|---|
| host | string | Required. |
| dbname | string | Optional. |
| user | string | Required. |
| password | string | Required. |
| charset | string | Optional, default is utf8mb4. |
Contributing
Any changes to the Project must abide by PSR Standards (PSR 2 - 12, PSR4 and others where applicable).
Please run phpcs before committing any code.
./vendor/bin/phpcs --standard=psr2 src/
gonzie/pdoload 适用场景与选型建议
gonzie/pdoload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 192 次下载、GitHub Stars 达 13, 最近一次更新时间为 2018 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdo」 「load balancer」 「load balancing」 「read write」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gonzie/pdoload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gonzie/pdoload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gonzie/pdoload 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LazyPDO is a set of wrappers over PHP's standard PDO and PDOStatement classes. It enables lazy loading, serialization and decoration.
Dibi is Database Abstraction Library for PHP
Ajax Box widget for Yii 2 Framework.
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Add health checks to your Craft website, useful when running inside of Docker
Load DOM document safety
统计信息
- 总下载量: 192
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-03