https://github.com/phlib/db-helper-replication
DB helpers to complement phlib/db
https://github.com/phlib/db-helper-replication
Last synced: 5 months ago
JSON representation
DB helpers to complement phlib/db
- Host: GitHub
- URL: https://github.com/phlib/db-helper-replication
- Owner: phlib
- License: lgpl-3.0
- Created: 2021-09-22T05:49:00.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-02-11T13:51:53.000Z (over 1 year ago)
- Last Synced: 2025-07-28T06:25:47.359Z (11 months ago)
- Language: PHP
- Size: 82 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# phlib/db-helper-replication
[](https://github.com/phlib/db-helper-replication/actions/workflows/code-checks.yml)
[](https://codecov.io/gh/phlib/db-helper-replication)
[](https://packagist.org/packages/phlib/db-helper-replication)
[](https://packagist.org/packages/phlib/db-helper-replication)

DB helpers to complement phlib/db
This package, *db-helper-replication*, is split out from *phlib/db-helper*
due to the additional process-control dependencies which users of the more
typical helpers may not require or have available.
## Installation
```php
composer require phlib/db-helper-replication
```
## Usage
### Replication
The Replication helper monitors replica lag, which it stores in Memcache. This
known lag can then be used to throttle long-running processes by introducing
variable amounts of sleep.
Set up replica monitoring using the CLI script
(you might consider using Monit to run this automatically):
```sh
./vendor/bin/db replication:monitor -c path/to/config.php -p /var/run/db-replication.pid -d start
```
```php
$config = require 'path/to/config.php';
$replication = Replication::createFromConfig($config);
while ([...]) {
[... some repetitive iteration, like writing thousands of records ...]
$replication->throttle();
}
```
Your config file might look something like this:
```php
'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;
```
## License
This package is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .