PHP Multi-database supported application design 1th/2 page _php Tutorial

Source: Internet
Author: User
So I think that in the master-slave database design, all session-related tables should be treated with special treatment. That is: All session data tables can be updated and queried, when a user visits the site, the user is bound to the specified database, all session access and query operations on this database. The session table does not synchronize, and other non-session class updates are also updated from the primary database. This does not really escape the session update when the database switch, so if you do not want to trouble, or the session is stored in the text of the good.
Sub-database design, it will be possible to improve the pressure performance of several grades, of course, the single execution efficiency will not be higher than the single database, after all, there is the efficiency of database switching. Sub-Library and master-slave database collocation is a good solution to improve the database concurrency bottleneck. Principle: Big Data volume, sub-database; Large traffic, master and slave. Many times, both are parallel (this article does not discuss the cache).
I think, if you want to achieve the sub-Library and master-slave relationship, then the number of database servers will be very considerable, in the application at any time to switch to a server, will be very headache, configuration replacement, variable name, is there a lot of it? How to find a better solution will be the topic of this article.
The first is the problem of database. Under what circumstances is the sub-Library? Perhaps some people still do not understand why to divide the library, I briefly say my own experience speculation. For example a blog program, the general design is to store the log in a log table. If it is a multi-user blog, then will be associated with a UID, if the amount of data is small, so the design is not a problem, but the log is huge, a day there are hundreds of thousands of logging input, and the amount of traffic is relatively considerable time, I think it is impossible for each user to access the log list, To find a few of the data tables that contain tens of millions of log records, the efficiency is visible. This is the time to take into account the problem of sub-Library. How to divide? There is a very simple sub-table method, that is, according to the UID section, logs are recorded in each database, of course, the distribution needs to be adjusted according to the previous statistical results, because the user log distribution is certainly not uniform. Set the UID segment, and then, based on the UID index to the specified database configuration, create a database object. The configuration information might look like this:
Copy CodeThe code is as follows:
$configs [' Db_info '] [' blog '][0] = array (
' Db_host ' = ' 192.168.0.1 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' blog '][1] = array (
' Db_host ' = ' 192.168.0.2 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' blog '][2] = array (
' Db_host ' = ' 192.168.0.2 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
//... There's a lot more.

As for which server to choose, just make a simple match on the UID.
Again, the master-slave database is mentioned. Under what circumstances is a master-slave database used? For example, a celebrity blog, the amount of access is quite large, there is no way to split his data again, this time to consider the master-slave database server, using multiple databases to divert. This applies to the master-slave and sub-Library, perhaps the above configuration information can be slightly changed.
Copy CodeThe code is as follows:
$configs [' Db_info '] [' blog '][0][' master '] = Array (
' Db_host ' = ' 192.168.0.1 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' blog '][0][' slave '][0] = array (
' Db_host ' = ' 192.168.0.2 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' blog '][0][' slave '][1] = array (
' Db_host ' = ' 192.168.0.3 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' blog '][1][' master '] = Array (
' Db_host ' = ' 192.168.0.4 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' blog '][1][' slave '][0] = array (
' Db_host ' = ' 192.168.0.5 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' blog '][1][' slave '][1] = array (
' Db_host ' = ' 192.168.0.6 ',
' Db_name ' = ' blog ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' Session '][0][' master '] = Array (
' Db_host ' = ' 192.168.0.7 ',
' Db_name ' = ' Session ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);
$configs [' Db_info '] [' Session '][1][' master '] = Array (
' Db_host ' = ' 192.168.0.8 ',
' Db_name ' = ' Session ',
' Db_user ' = ' root ',
' Db_pass ' = ',
);

Write here, I think all should know how to divide the table and allocate your database, and then I will say how to easily read the configuration information, how to integrate these configurations into your database driver.

http://www.bkjia.com/PHPjc/319320.html www.bkjia.com true http://www.bkjia.com/PHPjc/319320.html techarticle so I think that in the master-slave database design, all session-related tables should be treated with special treatment. That is: All session data tables can be updated and queried when a user visits the site ...

  • 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.