I made a WordPress plugin that imports some products (few hundreds) from API to Woocommerce. The problem is that after about 10 minutes (max execution time is set to unlimited) I’m getting this error multiple times with option_name different (there are some taxonomies for attributes):
WordPress database error Commands out of sync; you can't run this command now for query SELECT autoload FROM wp_options WHERE option_name = '_transient_wc_layered_nav_counts_pa_tehnologii-display' made by shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, WC_Cache_Helper::delete_transients_on_shutdown, delete_transient, delete_option
In other moments, the job which is importing products is stopping without any error message.
I tried the plugin on other hosts and no problem.
Any ideas?
2
Answers
This is a cache plugins error, try clearing your cache to see if it helps. otherwise completely uninstall and reinstall the cache plugin, maybe that will work. its caused by when a plugin leaves mess in database queries or doesnt close properly.
Also worth noting if your hosting is providing you the cache functionality and than you can safely disable the wordpress cache plugins.
In my case, it happened because of the conflicts between
mysqli_query
andmysqli_multi_query
when I was developing my own WP+React template.According to this doc and this question, it can cause "commands of sync" error.
In WordPress Database class,
wpdb
, it usesmysqli_query
. And I usedmysqli_multi_query
for my SQL code. They caused exactly the problem in the above 2 documents.The solution was described in the document, too.
I fixed it by adding the line below:
ps. I also learned that when an error message starts with "WordPress database error", it means the error came from the database side (mysql), not the WordPress side. Check this code. It can be helpful to search the error message with
mysql
keyword.