Skip to content
Home » Blog » Suspend WordPress Options Autoload

Suspend WordPress Options Autoload

WordPress stores its configuration by using key-value structure data that reside in the options table. By default named wp_options or wp_siteid_options for multisite. This is a simple method that should use for simple data. This option data can be accessed directly through /wp-admin/options.php.

Optimise Database Query

To make it reduce the query to the database for every single row, it has a field autoload, when set to “yes” all the data will be grouped in a single big chunk array called alloptions. Each time page is loaded, alloptions will use to get data instead of a query to the database. This is a good approach to making WordPress faster, but when the size of alloptions becomes bigger, this will crash a website when not enough memory to handle it.

Most plugins, by default, will use get_option and update_option to store their configuration that reflects the options table. WordPress transient also uses it. There is a good practice to remove the data when uninstalling the plugin and set an expiry time when using transient. But, not all plugins follow good practice. This is the big culprit when the size of alloptions is too big to handle.

Alloptions Size

The ideal size is 1 MB and below. When using in-memory solutions like Memcached or Redis for persistent object caching, Memcached will limit it to 1 MB if no further configuration. Redis can handle larger than 1 MB but it can make it a little bit slow because of operations serialising and unserializing the objects.

There is a misconception to handle this issue. Some advised setting autoload to “no” or other than “yes” will reduce alloptions sizes. By design, WordPress will treat all data autoloaded if no autoload is set to “yes”, which means still need one data set to “yes”.

WordPress wp_load_alloptions function
  1. The code section starts with the variable $alloptions_db where WordPress collects the data of options that have autoload with “yes”.
  2. If no option with “yes” is found, $alloptions_db will be set to “false”.
  3. If $alloptions_db is false, that’s where WordPress will recollect the options data without checking the autoload value.
  4. In the final process, WordPress will add the $alloptions_db data into the $alloptions variable.
$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" );
if ( ! $alloptions_db ) {
    $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
}
$wpdb->suppress_errors( $suppress );

$alloptions = array();
foreach ( (array) $alloptions_db as $o ) {
    $alloptions[ $o->option_name ] = $o->option_value;
}

Our Solutions

Docket Cache Configuration

Docket Cache has a different approach. Enabling “Suspend WP Options Autoload” options, Docket Cache will store non-prominent WordPress options to single data, including transient and other plugin data. This will ensure the size of alloptions is small and no query to makes to the database.

Leave a Reply

Your email address will not be published. Required fields are marked *