PHPackages                             zero1/magento2-splitdb - 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. zero1/magento2-splitdb

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

zero1/magento2-splitdb
======================

1.0.5(2y ago)3258↓50%2GPL-3.0-or-laterPHP

Since May 13Pushed 2y ago3 watchersCompare

[ Source](https://github.com/zero1limited/magento2-splitdb)[ Packagist](https://packagist.org/packages/zero1/magento2-splitdb)[ RSS](/packages/zero1-magento2-splitdb/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (7)Used By (0)

magento2-splitdb
================

[](#magento2-splitdb)

Ability to split database traffic to 1 or more readers. Allowing you to take advantage of an AWS reader endpoint for example.

Installation
------------

[](#installation)

These steps are intended to be carried out in a staging/development environment. If you don't have, look at [MDOQ](https://www.mdoq.io) which can provide multiple development environments quickly and cheaply.

1. `composer require zero1/magento2-splitdb`
2. `php bin/magento module:enable Zero1_SplitDb`
3. `php bin/magento setup:upgrade`
4. `php bin/magento deploy:mode:set production`

Configuration
-------------

[](#configuration)

To use separate endpoints for reading and writing to the database. You need to configure the endpoints in `app/etc/env.php`

Before

```
'db' => [
    'table_prefix' => '',
    'connection' => [
        'default' => [
            'host' => '[DB_HOST]',
            'dbname' => '[DB_NAME]',
            'username' => '[DB_USERNAME]',
            'password' => '[DB_PASSWORD]',
            'model' => 'mysql4',
            'engine' => 'innodb',
            'initStatements' => 'SET NAMES utf8;',
            'active' => '1',
        ]
    ]
],
```

After

```
'db' => [
    'table_prefix' => '',
    'connection' => [
        'default' => [
            'host' => '[DB_HOST]',
            'dbname' => '[DB_NAME]',
            'username' => '[DB_USERNAME]',
            'password' => '[DB_PASSWORD]',
            'model' => 'mysql4',
            'engine' => 'innodb',
            'initStatements' => 'SET NAMES utf8;',
            'active' => '1',
            'slaves' => [
                [
                    'host' => '[DB_READER_1_HOST]',
                    'username' => '[DB_READER_1_USERNAME]',
                    'password' => '[DB_READER_1_PASSWORD]',
                ],
                [
                    'host' => '[DB_READER_2_HOST]',
                    'username' => '[DB_READER_2_USERNAME]',
                    'password' => '[DB_READER_2_PASSWORD]',
                ]
            ]
        ]
    ]
],
```

- `slaves`: you can configure as many as you want. (Though with AWS you would only need to specify the single reader endpoint). The configuration for each slave is merged over the base config. So each slave will inherit all config values not defined. Each request will be locked to a single reader. (This is to stop multiple connections being opened)
- `excluded_areas`: you can also enforce the use of the writer endpoint for specific urls. By default this will be `'/checkout'` and `'/customer'`. If you don't want enforce for any areas supply an empty area ```
    'db' => [
        'table_prefix' => '',
        'connection' => [
            'default' => [
                'host' => '[DB_HOST]',
                'dbname' => '[DB_NAME]',
                'username' => '[DB_USERNAME]',
                'password' => '[DB_PASSWORD]',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8;',
                'active' => '1',
                'excluded_areas' => [],
                'slaves' => [
                    [
                        'host' => '[DB_READER_1_HOST]',
                        'username' => '[DB_READER_1_USERNAME]',
                        'password' => '[DB_READER_1_PASSWORD]',
                    ],
                    [
                        'host' => '[DB_READER_2_HOST]',
                        'username' => '[DB_READER_2_USERNAME]',
                        'password' => '[DB_READER_2_PASSWORD]',
                    ]
                ]
            ]
        ]
    ],
    ```

    If you want to enforce different or more areas, supply them in an array ```
    'db' => [
        'table_prefix' => '',
        'connection' => [
            'default' => [
                'host' => '[DB_HOST]',
                'dbname' => '[DB_NAME]',
                'username' => '[DB_USERNAME]',
                'password' => '[DB_PASSWORD]',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8;',
                'active' => '1',
                'excluded_areas' => [
                    '/checkout',
                    '/customer',
                    '/another-location',
                ],
                'slaves' => [
                    [
                        'host' => '[DB_READER_1_HOST]',
                        'username' => '[DB_READER_1_USERNAME]',
                        'password' => '[DB_READER_1_PASSWORD]',
                    ],
                    [
                        'host' => '[DB_READER_2_HOST]',
                        'username' => '[DB_READER_2_USERNAME]',
                        'password' => '[DB_READER_2_PASSWORD]',
                    ]
                ]
            ]
        ]
    ],
    ```

**N.B:** Don't forget to flush cache after updating the `app/etc/env.php` file and clear opache.

TODO
----

[](#todo)

- Reader exclusions DB/Adapter/Pdo/MysqlProxy.php:114 this is required because Magento saves the model, then instantly tries to load it. Need to locate the offending code or find another way around.

Debug
-----

[](#debug)

To debug which queries are going to which endpoint while the platform is in production mode add

```
'log_level' => \Monolog\Logger::INFO,
```

to the `default` node
then run `tail -f var/log/system.log | grep Zero1_SplitDb` an request some pages.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~239 days

Recently: every ~288 days

Total

6

Last Release

1000d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b08c35b603becab270a53db6ec969f48be0c353a20ee2985bb1a8ec5a9b64e9?d=identicon)[zero1](/maintainers/zero1)

---

Top Contributors

[![adamzero1](https://avatars.githubusercontent.com/u/6369163?v=4)](https://github.com/adamzero1 "adamzero1 (6 commits)")[![callum-zero1](https://avatars.githubusercontent.com/u/22055276?v=4)](https://github.com/callum-zero1 "callum-zero1 (3 commits)")[![reubenszero](https://avatars.githubusercontent.com/u/25824648?v=4)](https://github.com/reubenszero "reubenszero (1 commits)")

---

Tags

awsdatabasemagentowriterreadermagento 2Database Writer

### Embed Badge

![Health badge](/badges/zero1-magento2-splitdb/health.svg)

```
[![Health](https://phpackages.com/badges/zero1-magento2-splitdb/health.svg)](https://phpackages.com/packages/zero1-magento2-splitdb)
```

###  Alternatives

[vlucas/spot2

Simple DataMapper built on top of Doctrine DBAL

605392.8k7](/packages/vlucas-spot2)

PHPackages © 2026

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