query-monitor icon indicating copy to clipboard operation
query-monitor copied to clipboard

Fatal Error in DB Query Collector

Open emrikol opened this issue 9 months ago • 1 comments

Every now and then I get the following fatal error in Query Monitor. It's rather benign, but I figured I would share anyway. I took a quick through existing issues and didn't see anything. Apologies if it's a duplicate.

Uncaught Error: count(): Argument #1 ($value) must be of type Countable|array, null given
in /srv/htdocs/wp-content/plugins/query-monitor/collectors/db_queries.php on line 231

Call stack:

    QM_Collector_DB_Queries::process_db_object()
    wp-content/plugins/query-monitor/collectors/db_queries.php:77
    QM_Collector_DB_Queries::process()
    wp-content/plugins/query-monitor/classes/Collectors.php:84
    QM_Collectors::process()
    wp-content/plugins/query-monitor/classes/Dispatcher.php:123
    QM_Dispatcher::get_outputters('html')
    wp-content/plugins/query-monitor/dispatchers/Html.php:358
    QM_Dispatcher_Html::before_output()
    wp-content/plugins/query-monitor/dispatchers/Html.php:322
    QM_Dispatcher_Html::dispatch('')
    wp-includes/class-wp-hook.php:324
    WP_Hook::apply_filters(NULL, array)
    wp-includes/class-wp-hook.php:348
    WP_Hook::do_action(array)
    wp-includes/plugin.php:517
    do_action('shutdown')
    wp-includes/load.php:1279
    shutdown_action_hook()

This appears to be happening at: https://github.com/johnbillion/query-monitor/blob/482c5f5e2cf56abf134dcbcf396d99a2c44f5c63/collectors/db_queries.php#L231

I'm sure a quick is_countable() or array casting would "fix" it but not necessarily the underling reason why.

A refresh of the page always returns it back to working order.

PHP
Version 8.3.16
SAPI fpm-fcgi
User 150630904:site150630904
max_execution_time 850
memory_limit 512M
upload_max_filesize 2047M
post_max_size 2047M
display_errors
log_errors 1
Error Reporting 4983
Database
Server Version 10.6.15-MariaDB-log
Extension mysqli
Client Version 80316 (8.3.16)
User 150630904
Host 127.0.0.1
Database 150630904
innodb_buffer_pool_size 34359738368 (~32 GB)
key_buffer_size 134217728 (~128 MB)
max_allowed_packet 104857600 (~100 MB)
max_connections 500
WordPress
Version 6.7.2
Environment Type (Help) production
Development Mode (Help) empty string
WP_DEBUG false
WP_DEBUG_DISPLAY false
WP_DEBUG_LOG false
SCRIPT_DEBUG false
WP_CACHE true
CONCATENATE_SCRIPTS undefined
COMPRESS_SCRIPTS undefined
COMPRESS_CSS undefined
WP_ENVIRONMENT_TYPE production
WP_DEVELOPMENT_MODE empty string
Server
Software nginx
Version Unknown
IP Address 103.115.9.139
Host pool186-E02-23.dfw.atomicsites.net (Pressable)
OS Linux 5.10.0-23-amd64
Architecture x86_64
Basic Auth false

emrikol avatar Feb 12 '25 02:02 emrikol

Hello!

I have the same issue on a local Windows 10 environment with PHP 7.4 + memcached, when the plugin Object Cache 4 for everyone is enabled.

PHP Warning:  count(): Parameter must be an array or an object that implements Countable in \wp-content\plugins\query-monitor\collectors\db_queries.php on line 231

A quickfix is to change the line to:

$this->data->total_qs = is_countable($this->data->rows) ? count( $this->data->rows ) : 0;

hwkdev avatar Mar 14 '25 07:03 hwkdev

We're also experiencing this issue. I think the quick fix above would work. It happens on pages with no queries. While benign, it does cause issues, especially if you use a custom error handler.

mslinnea avatar Jul 01 '25 21:07 mslinnea

This is continuing to be an issue. It seems to be happening more with the ES 8 upgrade. I can reproduce on the /wp-admin/upload.php page as well as many other pages.

mslinnea avatar Sep 19 '25 20:09 mslinnea

I wonder if this is related to another issue I had seen with the Performance Lab and how Automattic's HyperDB manages its saved queries:

https://github.com/WordPress/performance/issues/2158

emrikol avatar Sep 22 '25 19:09 emrikol