brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: SAVEQUERIES records every wordpress database query with its time and caller

WordPress
~/tips/tip-wordpress-savequeries-wpdb-queries

define( 'SAVEQUERIES', true );

Stores each database query with its runtime and calling function for finding slow queries.

When a page is slow I want to see which query takes the time, and which function asked for it.

define( 'SAVEQUERIES', true );
// in a template, for admins only:
global $wpdb; if ( current_user_can( 'manage_options' ) ) { var_dump( $wpdb->queries ); }

With SAVEQUERIES on, $wpdb->queries becomes an array of entries, each with the SQL text, the time it took and the functions that called it. Sort by time to find the slow one. It adds overhead to every request and keeps all queries in memory, so use it on a staging copy or only for a short test, and never output the array to visitors. A plugin like Query Monitor shows the same information in a nicer way.

Further reading: WordPress: Debugging in WordPress

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link