jeremiah-shaulov/pdoi 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jeremiah-shaulov/pdoi

Composer 安装命令:

composer require jeremiah-shaulov/pdoi

包简介

Improved PDO for MySQL connections pooling

关键字:

README 文档

README

This library provides class whose API matches PDO API, and can be used as PDO replacement with little application changes. This class is called Pdoi. It supports most (but not all) PDO features. For drivers other than MySQL, it works exactly like PDO (function calls are forwarded to internal PDO instance), and for MySQL it explicitly uses mysqli extension.

This is to achieve 2 goals:

  1. Saner connections pooling.
  2. Access to mysqli-specific features.

About database connections pooling

As of January 2021, my eyes don't see usable database connections pooling solution in PHP world.

Persistent connections can be created with mysqli using "p:" prefix for hostname. And with PDO they can be created with help of PDO::ATTR_PERSISTENT attribute. Together with PHP-FPM process pool this can build up the true database connections pooling system.

This worked even on PHP4, but nobody practically used them, because there are problems reusing a dirty connection.

  1. SET @flag=1 issued once, will be initially set on next connection usage.
  2. Started and not committed transactions will hold locks on touched rows.
  3. SELECT Get_lock('Busy', 10) will prevent other parallel connections in pool from entering critical section.

Current persistent connections implementation in mysqli and PDO, as of January 2021, resets connection state by calling mysqli_change_user() function. But my experience reveals that user-locks are not released. I suppose that this function is called when a connection is picked up from pool, before using it. So whole time period since the connection was left alone, and till it's new usage (that can not happen at all), locks are locking what they want to lock.

Each connection should be reset immediately at script end. This library calls mysqli_change_user() in destructor of Pdoi object. What i love in PHP is reference-counting objects, and that destructors are called immediately when the object is not in use.

Installation

Create a directory for your application, cd to it, and issue:

composer require jeremiah-shaulov/pdoi

Example

<?php

require_once 'vendor/autoload.php';
use Pdoi\Pdoi as Pdo;

$db = new Pdo
(	'mysql:host=localhost',
	'root',
	'',
	[	PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
		PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
		PDO::MYSQL_ATTR_MULTI_STATEMENTS => false,
		PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
		PDO::ATTR_PERSISTENT => true,
	]
);

var_dump($db->query("SELECT Connection_id()")->fetchColumn());

Running this example from CLI will show different Connection_id() each time, because there will be only 1 connection in process lifecycle. But running from PHP-FPM will show that the same connection numbers appear many times.

jeremiah-shaulov/pdoi 适用场景与选型建议

jeremiah-shaulov/pdoi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「db-pool」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jeremiah-shaulov/pdoi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jeremiah-shaulov/pdoi 我们能提供哪些服务?
定制开发 / 二次开发

基于 jeremiah-shaulov/pdoi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

与 jeremiah-shaulov/pdoi 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-28