詳細検索

Things to keep in mind when using HyperDB database duplexing in WordPress

Avatar
by maeno
2 min read

Things to keep in mind when using HyperDB database duplexing in WordPress
Translated from 日本語 • View original

When building a commercial website with WordPress, it is common to separate the web application server from the database server and duplex the database side. This is simply to improve service performance by distributing the load on database access, and in the sense that the positive database can be recovered from the database of the mirrored secondary node in the event of a failure, it can also reduce the risk of "data loss", which is the worst case for the service.
WordPress has a drop-in called "HyperDB" that can also support mirrored database configurations of such primary and secondary nodes. This allows you to aggregate database updates to the master database only, and distribute database references between master and secondary.
(* The method of database redundancy by "HyperDB" drop-in is QuickKnowLedge: WordPress load balancing using MySQL HyperDB + Keepalid. etc. are explained in detail. )

Now, if your WordPress site using HyperDB is extending its own database access processing in a way that does not rely on WordPress's core processing, you may encounter problems.
What kind of case is when you use the global variable "$wpdb" in the WordPress database control system outside of the WordPress page.

For example, if you call your own PHP directly from a WordPress post in Ajax or other software, and then access the WordPress database within that PHP. When using the global variable "$wpdb" for database access in an external program independent of such a WordPress group of programs,
[code lang="php" light="true"]require_once('./wp-config.php');[/code] … And if you include the configuration file as described above, it will not work as soon as you enable "HyperDB".

In this case, we will normalize it by changing the included file from the configuration file to the blog header.
[code lang="php" light="true"]require_once('./wp-blog-header.php');[/code]
In particular, there was no change in performance even after changing the include file, so in conclusion, it seems safe to include "wp-blog-header.php" when using "$wpdb" in an external program.

Related Articles