How to Reduce and clean the options table of wp session entries

Every visitor will have a temporary session stored on the options table. The session tokens are very small, it is a server side cookie store. The sessions automatically purge after 30 minutes of inactivity.

But when its not not purge automatically then it create a problem and your database size increase too much that effected your site speed.

So we should need to delete these entries manually or create a plugin for that i will show you how can be delete these through phpmyadmin command or by a plugin.

By Mysql command:

1
2
3
DELETE
FROM `wp_options`
WHERE option_name LIKE '_wp_session%'

You should create a plugin that will schedule an event that occurs daily:

1
2
register_activation_hook(__FILE__, 'my_activation');
add_action('my_daily_event', 'do_this_daily');

function my_activation() {
wp_schedule_event(time(), ‘daily’, ‘my_daily_event’);
}

function do_this_daily() {
$wpdb->query(
“DELETE FROM $wpdb->options
WHERE option_name LIKE ‘_wp_session%’

)
}

Leave a Reply