PHPackages                             connehito/cakephp-master-replica - 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. connehito/cakephp-master-replica

AbandonedArchivedCakephp-plugin[Database &amp; ORM](/categories/database)

connehito/cakephp-master-replica
================================

Provides the features for multiple database connections as master/replica and switching.

2.0.0(6y ago)1267.1k—9.7%2MITPHPPHP &gt;=7.2

Since Oct 13Pushed 1y agoCompare

[ Source](https://github.com/Connehito/cakephp-master-replica)[ Packagist](https://packagist.org/packages/connehito/cakephp-master-replica)[ RSS](/packages/connehito-cakephp-master-replica/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

\[Archived\] CakePHP Master Replica Plugin
==========================================

[](#archived-cakephp-master-replica-plugin)

Use CakePHP native features introduced from [4.5](https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html#database) if you want to switch Database roles.

This project has been archived and is no longer actively maintained because several years have passed without active maintenance.

We appreciate the support and contributions from the community over the years. While this repository will remain available in read-only mode, there will be no further updates or maintenance. Thank you for your understanding and support.

---

The datasource for CakePHP.This plugin enables one-connection to act as two(or more) roles, like master(read-write) and replica(read-only).

[![No Maintenance Intended](https://camo.githubusercontent.com/d904056147052e22d8e1c7f46bb50293ed2aeb4c43ead9a2d0cf7a48b46d0562/687474703a2f2f756e6d61696e7461696e65642e746563682f62616467652e737667)](http://unmaintained.tech/)[![Build Status](https://camo.githubusercontent.com/cef37743d5a521811fc015cfd387227c61c6904449b2c005261b43f7f25570bf/68747470733a2f2f7472617669732d63692e636f6d2f436f6e6e656869746f2f63616b657068702d6d61737465722d7265706c6963612e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Connehito/cakephp-master-replica)[![codecov](https://camo.githubusercontent.com/309a43ff9c344bbd67b2d0d82df10b324018ce2b5b55163e844029937ab171a9/68747470733a2f2f636f6465636f762e696f2f67682f436f6e6e656869746f2f63616b657068702d6d61737465722d7265706c6963612f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Connehito/cakephp-master-replica)[![Latest Stable Version](https://camo.githubusercontent.com/6bc8e83b2b4de60b8297764f7118841ef8af55c86125b8dff37033b8e06a9eec/68747470733a2f2f706f7365722e707567782e6f72672f636f6e6e656869746f2f63616b657068702d6d61737465722d7265706c6963612f762f737461626c65)](https://packagist.org/packages/Connehito/cakephp-master-replica)[![Total Downloads](https://camo.githubusercontent.com/9d0d1e431be445f76b87476a075db6865665963e1232919612795e7437c30c28/68747470733a2f2f706f7365722e707567782e6f72672f636f6e6e656869746f2f63616b657068702d6d61737465722d7265706c6963612f646f776e6c6f616473)](https://packagist.org/packages/Connehito/cakephp-master-replica)[![License](https://camo.githubusercontent.com/794598e4f6803b6074a6c24f11e30aac0bcee4b7b5890871fce378654dd42720/68747470733a2f2f706f7365722e707567782e6f72672f636f6e6e656869746f2f63616b657068702d6d61737465722d7265706c6963612f6c6963656e7365)](https://packagist.org/packages/Connehito/cakephp-master-replica)

Supports
--------

[](#supports)

- PHP 7.2+
- CakePHP 4.0+

💡 For CakePHP3.x, use `1.x` branch.

Usage
-----

[](#usage)

1. Install plugin `composer require connehito/cakephp-master-replica`
2. Set your connections(e.g. in `config/app.php` datasource. It requires `roles` property.

### Example

[](#example)

Set up your database configuration.

- Databse-A(for master): mysql;host=db-host,databasename=app\_db,login=root,pass=password
- Databse-B(for replica): mysql;host=db-host,databasename=app\_db,login=read-only-user,pass=another-password
- Databse-C(for replica): mysql;host=replica-host,databasename=app\_db,login=read-only-user,pass=another-password

```
// app.php
// return [
    'Datasources' => [
        'driver' => Cake\Database\Driver\Mysql::class,
        'className' => Connehito\CakephpMasterReplica\Database\Connection\MasterReplicaConnection::class,
        'host' => 'replica-host',
        'database' => 'app_db',
        'roles' => [
            'master' => ['host' => 'db-host', 'username' => 'root', 'password' => 'password'],
            'secondary' => ['host' => 'db-host', 'username' => 'read-only-user', 'password' => 'another-password'],
            'tertiary' => ['username' => 'read-only-user', 'password' => 'another-password'],
        ]
    ]
```

In each roles, you can set specific values and override them.

In app, now you can connect to database master or replica db as you like 🎉

```
// as default, connect with `master` role.
$usersTable->save($usersTable->newEntity(['name' => 'hoge']));

// switch to `replica` role
\Cake\Datasource\ConnectionManager::get('default')->switchRole('secondary');
// Or you can get Connection via Table
$usersTable->getConnection()->switchRole('tertiary');
```

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome on GitHub at

- Please fix all problems with PHPUnit, PHPStan, PHP\_CodeSniffer before send pull request 😄
- You can build development env in local with `tests/test_app/docker-compose.yml` 🏇

License
-------

[](#license)

The plugin is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~67 days

Total

3

Last Release

2321d ago

Major Versions

1.x-dev → 2.0.02020-02-24

PHP version history (2 changes)1.0.0PHP &gt;=7.0.0

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4102447?v=4)[Connehito](/maintainers/connehito)[@Connehito](https://github.com/Connehito)

![](https://avatars.githubusercontent.com/u/907122?v=4)[Hideki Kinjyo](/maintainers/o0h)[@o0h](https://github.com/o0h)

---

Top Contributors

[![o0h](https://avatars.githubusercontent.com/u/907122?v=4)](https://github.com/o0h "o0h (31 commits)")[![fortkle](https://avatars.githubusercontent.com/u/1576804?v=4)](https://github.com/fortkle "fortkle (2 commits)")[![otukutun](https://avatars.githubusercontent.com/u/1199643?v=4)](https://github.com/otukutun "otukutun (2 commits)")[![fabiofdsantos](https://avatars.githubusercontent.com/u/8303937?v=4)](https://github.com/fabiofdsantos "fabiofdsantos (1 commits)")

---

Tags

cakephp-plugincakephp3cakephp4

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/connehito-cakephp-master-replica/health.svg)

```
[![Health](https://phpackages.com/badges/connehito-cakephp-master-replica/health.svg)](https://phpackages.com/packages/connehito-cakephp-master-replica)
```

###  Alternatives

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k48.7M460](/packages/robmorgan-phinx)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/packages/jdorn-sql-formatter)[cakephp/migrations

Database Migration plugin for CakePHP

13812.9M299](/packages/cakephp-migrations)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[cakephp/orm

CakePHP ORM - Provides a flexible and powerful ORM implementing a data-mapper pattern.

151252.5k83](/packages/cakephp-orm)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
