Search This Blog
Popular Posts
-
Elegant Themes has been developing WordPress themes for a long time. It has developed lots of popular themes including Divi, Nexus, Fa...
-
How to start a blog or website in 5 minutes with WordPress. After publishing the post on how I started blogging full-time, I'v...
-
Hello there! My blog post 'Spikes' was published on Sept. 22nd; however, the post before it called 'Flow' was published on...
-
Hot Off the Press Jenny Diski on Writing, Love, and Cancer Photo by heipei Mark Armstrong Jun 17, 2015 @ 2:07 ...
-
It has not only changed the traditional perspective of buyers and sellers, but also revolutionized the entire concept of retail busine...
-
Chukwuemeka Fred Agbata Jnr. Two weeks ago, I started a piece focusing on mobile apps that can aid your productivity. I already wrote ...
-
Content marketing and SEO has evolved quite a bit over the past few years. Google re...
-
What is the exact URL of the site you deleted? If you are referring to a site that was hosted by wordpress.COM, the relevant wordpress.C...
-
WordPress has rolled out a new version dubbed 4.2.3 of its content management system (CMS) to patch a critical cross-site scripting (XSS) vu...
-
Hello my Windows Insiders! This week we have been hosting a Continuum App Contest in Redmond and it's been really cool to see the awes...
Blog Archive
- December (18)
- November (29)
- October (27)
- September (29)
- August (31)
- July (30)
- June (29)
- May (29)
- April (30)
- March (31)
- February (28)
- January (31)
- December (31)
- November (30)
- October (31)
- September (30)
- August (43)
- July (42)
- June (33)
- May (43)
- April (36)
- March (37)
- February (31)
- January (4)
- December (1)
- November (1)
- October (24)
- September (24)
- August (25)
- July (28)
- June (18)
- September (1)
Total Pageviews
Blogroll
Use MySQL persistent database connection for WordPress on Azure App
1. MySQL persistent database connection is recommended for improving performance, it is preferred when you use a remote database server.
For more information, https://azure.microsoft.com/en-us/blog/how-to-run-wordpress-site-on-azure-websites/
2. Persistent database connection has "timeout" implemented, when you try to use the existing connection after long idle time, you may get
PHP warning "MySQL server has gone away" because it timed out. To prevent this error, use mysql_ping (or mysqli_ping).
"mysql_ping" checks whether or not the connection to MySQL server is active and working, if the connection is down, it attempts to reconnect.
3. By default, WordPress use regular (non-persistent) connection. To use persistent database connection, you can modify the code in wp-includes/wp-db.php.
Find original code:
if ( WP_DEBUG ) { $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); } else { $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); }
...
Modify it to:
if ( WP_DEBUG ) { if ( !mysql_ping($this->dbh) ) { $this->dbh = mysql_pconnect( $this->dbhost, $this->dbuser, $this->dbpassword, $client_flags ); } } else { if ( !mysql_ping($this->dbh) ) { $this->dbh = @mysql_pconnect( $this->dbhost, $this->dbuser, $this->dbpassword, $client_flags ); } }
For mysqli, find original code:
if ( WP_DEBUG ) { mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); } else { @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); }
...
Modify it to:
if ( WP_DEBUG ) { if ( !mysqli_ping($this->dbh) ) { mysqli_real_connect( $this->dbh, "p:".$host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); } } else { if ( !mysqli_ping($this->dbh) ) { @mysqli_real_connect( $this->dbh, "p:".$host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); } }
Note: The code is base on the current version WordPress 4.3.1
{{html Body}}Source: Use MySQL persistent database connection for WordPress on Azure App
0 comments:
Post a Comment