定制 zero1/magento2-splitdb 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zero1/magento2-splitdb

最新稳定版本:1.0.5

Composer 安装命令:

composer require zero1/magento2-splitdb

包简介

README 文档

README

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

Installation

These steps are intended to be carried out in a staging/development environment. If you don't have, look at MDOQ 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

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

  • 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

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.

统计信息

  • 总下载量: 286
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固