PHPackages                             phlib/db-helper-replication - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. phlib/db-helper-replication

ActiveLibrary[Database &amp; ORM](/categories/database)

phlib/db-helper-replication
===========================

DB helpers to complement phlib/db

0.4.1(1y ago)04LGPL-3.0PHP ^8.1

Since Sep 22Compare

[ Source](https://github.com/phlib/db-helper-replication)[ Packagist](https://packagist.org/packages/phlib/db-helper-replication)[ RSS](/packages/phlib-db-helper-replication/feed)WikiDiscussions Synced 1w ago

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

phlib/db-helper-replication
===========================

[](#phlibdb-helper-replication)

[![Code Checks](https://camo.githubusercontent.com/d69adfcb30d3b1f7d9dc8fcfcdc4e8e2044b9df55bef2ce20d131bb140dd0a13/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70686c69622f64622d68656c7065722d7265706c69636174696f6e2f636f64652d636865636b732e796d6c3f6c6f676f3d676974687562)](https://github.com/phlib/db-helper-replication/actions/workflows/code-checks.yml)[![Codecov](https://camo.githubusercontent.com/293f53370ca05bb4f759283403ca9f6c1295d2651d4b3c5564343043281a90e6/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f70686c69622f64622d68656c7065722d7265706c69636174696f6e2e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/gh/phlib/db-helper-replication)[![Latest Stable Version](https://camo.githubusercontent.com/1c75dd7740a9ef8d1d66d099cc3caff7d17d7be129669fa70394b08831d9e997/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c69622f64622d68656c7065722d7265706c69636174696f6e2e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/db-helper-replication)[![Total Downloads](https://camo.githubusercontent.com/4491c07a2b8e28c9fa928c674d2a17d777e369bee649edf6c0b7274a7d68d287/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c69622f64622d68656c7065722d7265706c69636174696f6e2e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/db-helper-replication)[![Licence](https://camo.githubusercontent.com/8317293db80167843fe3573bbb2a171c30b20bc80bce0da6c0cb0cc8d3c0e212/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f64622d68656c7065722d7265706c69636174696f6e2e737667)](https://camo.githubusercontent.com/8317293db80167843fe3573bbb2a171c30b20bc80bce0da6c0cb0cc8d3c0e212/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f64622d68656c7065722d7265706c69636174696f6e2e737667)

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
------------

[](#installation)

```
composer require phlib/db-helper-replication
```

Usage
-----

[](#usage)

### Replication

[](#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):

```
./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();
}
```

Your config file might look something like this:

```
