MySQL Persistent Connection can be used to Optimize WordPress Page Loading Speed. It depends on server configuration, otherwise performance will degrade. By default, MySQL Persistent Connection is not enabled in WordPress. We can, however force WordPress to use MySQL Persistent Connection. Here is how to force WordPress to use MySQL Persistent Connection, what should be the monitoring tools and on what Server Configuration MySQL Persistent Connection probably work better.
What is MySQL Persistent Connection
When we are using non persistent connection, every time WordPress MySQL queries are opening and closing the database connection. This function to some extent remains even when we use a Cache Plugin. Because there are some PHP calls which are not Cached. Sometimes we force with HTML comments to make it work as live, non cached. But in case of forced MySQL Persistent Connection usage, when connecting to the database, the call / function will try to find an already opened with the same username and password. So, if one connection is already made before, it will not require to check the username and password. So logically using MySQL Persistent Connection can at least work better for backend of the WordPress, not if frontend.
How to force MySQL Persistent Connection in WordPress
Basically editing one file in wp-includes folder. That file is wp-db.php ; there are three lines (in WordPress 3.3.1) where mysql_connect() has been used. If we replace these with mysql_pconnect() then we are basically forcing MySQL Persistent Connection. Actually editing only @mysql_connect will serve the purpose. MySQL is a very big ocean and I have very little knowledge about MySQL, I think it is better to change all the three mysql_connect to mysql_pconnect to force MySQL Persistent Connection.
For whom MySQL Persistent Connection will work better
Just like we are using a server platform with virtually no limit of physical RAM and our PHP memory can be increased for WordPress to any digit. If there is very less PHP memory then forcing MySQL Persistent Connection will return 500 server error. You will get these in your PHP error log.
Tools to check health and performance after forcing MySQL Persistent Connection
First tool to check the efficiency of MySQL Persistent Connection is webpagetest.org – to check the Page Loading Speed after forcing MySQL Persistent Connection. Second is your PHP error log to check errors after using MySQL Persistent Connection.
Our test and result with MySQL Persistent Connection
We have tested this MySQL Persistent Connection on 5 WordPress installation with medium to quite high traffic. We have noted almost no difference in page loading speed after forcing MySQL Persistent Connection. To show you the performance after forcing MySQL Persistent Connection, here are two screenshots (like those hair growing lotion adverts!) :
Here is the performance before forcing MySQL Persistent Connection :
Here is the performance after forcing MySQL Persistent Connection :
Inference on MySQL Persistent Connection for WordPress
You can check our one of other site Daily Medico ; we kept the forced MySQL Persistent Connection on for this one. Its loading very fast on ‘feel’ – within 1.3 seconds but the problem is there are PHP errors are also getting generated. So the crux is probably forcing MySQL Persistent Connection even on high end cloud server with loadbalancers is not very safe although it might increase the page loading speed a bit, at least the ‘feel’ becomes ‘its loading faster’.
Tagged With wordpress persistent database connection , wordpress mysql optimization , wordpress optimization speed , wordpress database connection limit , PHP MySQL Allow Persistent Connections: On , Persistent Connection wordpress , persistent connection updater wordpress , persist connection to database on wordpress , optimize wordpress website speed , optimize mysql server for wordpress