PHP master-Slave separation distributed processing ____php

Source: Internet
Author: User

The so-called master-slave separation is written from the primary database, from the server to read data, whether a main one from or a master from, the server is instantaneous synchronization, the program end only need to process is written in the primary server write, read in from the server read.

First, thinkphp to achieve master-slave separation

thinkphp Support master-slave separation, configuration is also very easy

' Db_deploy_type ' => 0,//Database Deployment mode: 0 Centralized (single server), 1 distributed (Master-slave server)
' Db_rw_separate ' => false,//database read/write separate master-slave valid
' Db_host ' = ' 192.168.1.101,192.168.1.102 ',

' Db_user ' => ' user1,user2 ',

' Db_pwd ' => ' pwd1,pwd2 ',

The default first database 78 is the primary database, responsible for the write operation, the second 60 is responsible for reading, thinkphp will automatically recognize read and write, and then assign the link to the corresponding database, to achieve the effect of read and write separation.

Precautions:
1. If you are setting up a distributed database, DB_DSN configuration is not currently supported.
2. If you are currently using a distributed database and you have set up a read-write separation, the query method is always performed at the read server, so the query method corresponds to a read operation, regardless of what your SQL statement is.
3. If you are currently using a distributed database and you have set up a read-write separation, the Execute method is always executed at the write server, so the Execute method corresponds to the write operation, regardless of what your SQL statement is.
Therefore, ' db_dsn ' => ' Mysql:host=192.168.100.60;dbname=51fanli_cang ', this way does not support master-slave separation, need to change.
When using the original ecological SQL statement to write operations, to use Execute, read the operation to use query, remember, otherwise disorderly dropped.

Second, ecshop reading and writing separation

http://blog.csdn.net/very_loong/article/details/7999895

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.