Skip to content

Instantly share code, notes, and snippets.

@crewstyle
Last active March 9, 2019 12:56
Show Gist options
  • Save crewstyle/8200905de66ea9328a754a0678c1da8f to your computer and use it in GitHub Desktop.
Save crewstyle/8200905de66ea9328a754a0678c1da8f to your computer and use it in GitHub Desktop.
WordPress ~ Close database connections - #security #optimisation
<?php
/**
* Close database connections
*
* It's very dangerous to let connections opened. In a website
* with high traffic volume, you can kill your database just
* because of unclosed DB connections.
* This little snippet prevent that drama ;)
*
* @uses mysql_close() To close all DB connections.
* @see https://github.com/crewstyle/clean-wordpress
*/
add_action('shutdown', '_cw_close_db_link', 99);
function _cw_close_db_link()
{
global $wpdb;
unset($wpdb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment