php’s microtime() function

This entry is part 3 of 3 in the series php features

php’s microtime( true ) function returns a floating point number of seconds since the UNIX epoch. On my computer each call takes about 200ns. The same is true of the time() and hrtime() functions. hrtime() is more modern and gives nanosecond resolution, so use it if possible. It’s available in php 7.3 and beyond. By … Read more

WordPress’s Query Monitor: slow and duplicate queries?

John Blackbourn’s Query Monitor plugin sometimes reports slow queries and duplicate queries. How can you interpret these reports? What are slow and duplicate queries? Slow queries Query Monitor defines slow queries as those that take more than 50 milliseconds (1/20th of a second). Query Monitor shows query times in seconds in the rightmost column of … Read more

WordPress user roles: how are they stored?

WordPress lets site administrators assign roles to their registered users. These roles are, on a standard WordPress installation, Administrator, Editor, Author, Contributor, and Subscriber. Plugins can add custom roles. For example, WooCommerce adds Customer and Shop Manager roles. The roles assigned to each user are stored in the wp_usermeta table. In an ordinary single-site install … Read more

WooCommerce key improvement

WordPress’s WooCommerce plugin uses a table called wp_woocommerce_order_itemmeta as an extensible key-value storage mechanism for order line items. Its parent table is wp_woocommerce_order_items. These two tables work similarly to wp_postmeta and wp_posts, and have the same performance issues. In large sites with a long history of orders, lookup may be slow. wp_woocommerce_order_itemmeta This DDL, usable … Read more

Elementor Performance

I’m seeing a lot of questions about sites being slow. Anecdotally, it seems like many of those are Elementor sites. So a database performance fanatic like me smells an opportunity to make improvements. Some of the WordPress punditocracy says “don’t use Elementor”. But, they have over ten million downloads. So let’s help those sites if … Read more

Optimizing WordPress Database Servers

It’s common, and frustrating, for WordPress sites to be slow. When a site is slow for visitors, they give up and go elsewhere. When the dashboard is slow for site owners and content editors, it makes it harder to maintain the site, post new stuff, and handle orders (if it’s a store). Database Optimization Plugins … Read more

Database Keys in Scalability Pro

Scalability Pro is a paid plugin for improving backend WordPress and WooCommerce performance. It does multiple things including query rewriting and memoization caching of some time-consuming database queries. One thing it does is add keys (indexes) to some WordPress tables. This article is a table-by-table analysis of some keys it adds, compared with the keys … Read more

Slow searching for WooCommerce orders

Background WooCommerce offers a search box on the WooCommerce -> Orders page. It lets a shop manager search orders, current and historic, for the customer’s name, address, email, and other data. It also searches the names of products and shows orders containing those products. On large sites with many orders, the search is astoundingly slow. … Read more

SQL_CALC_FOUND_ROWS in WordPress

Background When presenting so-called “archive” pages of content to users WordPress uses the notorious SQL_CALC_FOUND_ROWS MySQL extension to populate its display that looks something like this. This kind of user interface is known as “pagination” because it lets the user select pages of results. So, it’s really useful. The phrase “Showing 1-12 of 1348 results” … Read more