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)1265.9k↓30.6%2MITPHPPHP &gt;=7.2

Since Oct 13Pushed 1y ago1 watchersCompare

[ 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 1mo ago

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 85% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community14

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

2276d 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://www.gravatar.com/avatar/ebbe04556134211d3112ca13deb324943262ddc9a7740a6412cca6067952f555?d=identicon)[connehito](/maintainers/connehito)

![](https://www.gravatar.com/avatar/7308bfca1f335f367cd1f08501356d6bc065f42e115bdd6bbcd140f0df90fd55?d=identicon)[o0h](/maintainers/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.5k46.2M405](/packages/robmorgan-phinx)[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)[usmanhalalit/laracsv

A Laravel package to easily generate CSV files from Eloquent model.

6151.7M4](/packages/usmanhalalit-laracsv)

PHPackages © 2026

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