cloudtay / ripple-rdo
There is no license information available for the latest version (dev-main) of this package.
dev-main
2024-10-31 16:19 UTC
Requires
- php: >=8.1
- ext-openssl: *
- ext-pdo: *
- cloudtay/ripple: ^1.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
This package is auto-updated.
Last update: 2024-10-31 19:14:03 UTC
README
项目简介
基于PHP
自举的PDO
驱动, 目前仅支持MySQL
数据库。
兼容版本
兼容版本指的是在该版本下测试通过的版本号,不代表其他版本不可用
快速安装
composer require cloudtay/ripple-rdo
基础用法
就像使用
PDO
一样使用RDO
驱动
include __DIR__ . '/../vendor/autoload.php'; /** * @var \PDO $rdo 已继承不冲突 */ $rdo = new \Ripple\RDO( 'mysql:host=127.0.0.1;port=3306;dbname=hello_world;charset=utf8', 'benchmarkdbuser', 'benchmarkdbpass', ); echo 'connection established' , \PHP_EOL; $statement = $rdo->prepare("UPDATE `World` SET `randomNumber` = ? WHERE `id` = 1;"); $statement->execute([':randomNumber' => \rand(1, 10000)]); echo 'update executed ' , $statement->rowCount() , \PHP_EOL;
异步用法
include __DIR__ . '/../vendor/autoload.php'; \Co\async(static function(){ echo 'coroutine 1 start ' , microtime(true) , \PHP_EOL; $rdo1 = new \Ripple\RDO( 'mysql:host=127.0.0.1;port=3306;dbname=hello_world;charset=utf8', 'benchmarkdbuser', 'benchmarkdbpass', ); //模拟耗时一秒查询 $rdo1->query("SELECT SLEEP(1);"); echo 'coroutine 1 end ' , microtime(true) , \PHP_EOL; }); \Co\async(static function(){ echo 'coroutine 2 start ' , microtime(true) , \PHP_EOL; $rdo2 = new \Ripple\RDO( 'mysql:host=127.0.0.1;port=3306;dbname=hello_world;charset=utf8', 'benchmarkdbuser', 'benchmarkdbpass', ); //模拟耗时一秒查询 $rdo1->query("SELECT SLEEP(1);"); echo 'coroutine 2 end ' , microtime(true) , \PHP_EOL; }); \Co\wait();
附录
上述例子中的数据库一键部署
docker run -d --name tfb-database -p 3306:3306 techempower/mysql:latest