phlib / db-helper-replication
DB助手,用于补充phlib/db
0.3.1
2023-10-15 07:42 UTC
Requires
- php: ^7.4 || ^8.0
- ext-pdo: *
- phlib/console-configuration: ^2
- phlib/console-process: ^3 || ^4
- phlib/db: ^2
- symfony/console: ^5 || ^6
Requires (Dev)
Suggests
- ext-memcached: Use to cache lag values
README
DB助手,用于补充phlib/db
此包,db-helper-replication,由于额外的进程控制依赖,从phlib/db-helper中分离出来,这些依赖可能是更多典型助手用户不需要或不可用的。
安装
composer require phlib/db-helper-replication
使用
复制
复制助手监控副本延迟,它将延迟存储在Memcache中。然后可以使用已知的延迟通过引入可变数量的睡眠来限制长时间运行的过程。
使用CLI脚本设置副本监控(您可能考虑使用Monit自动运行此脚本)
./vendor/bin/db replication:monitor -c path/to/config.php -p /var/run/db-replication.pid -d start
$config = require 'path/to/config.php'; $replication = Replication::createFromConfig($config); while ([...]) { [... some repetitive iteration, like writing thousands of records ...] $replication->throttle(); }
您的配置文件可能看起来像这样
<?php $config = [ // primary 'host' => '10.0.0.1', 'username' => 'foo', 'password' => 'bar', 'replicas' => [ [ 'host' => '10.0.0.2', 'username' => 'foo', 'password' => 'bar', ], ], 'storage' => [ 'class' => \Phlib\DbHelperReplication\Replication\Memcache::class, 'args' => [[]], ], ]; return $config;
许可证
此包是免费软件:您可以在自由软件基金会发布的GNU Lesser General Public License的条款下重新分发和/或修改它,无论是许可的第3版,还是(根据您的选择)任何后续版本。
本程序分发时,希望它会是有用的,但没有任何保证;甚至没有关于其商业性或适用于特定目的的隐含保证。有关详细信息,请参阅GNU Lesser General Public License。
您应该已经收到GNU Lesser General Public License的副本。如果没有,请参阅https://gnu.ac.cn/licenses/。