inpsyde / WP-Stash

Bridge between WordPress and StashPHP, providing a PSR6-compliant caching system for WordPress
https://inpsyde.com/en/wordpress-caching-system-wpstash/
GNU General Public License v2.0
51 stars 12 forks source link

Compatability with Query Monitor #1

Closed thefrosty closed 6 years ago

thefrosty commented 6 years ago

I'm getting errors when the Query Monitor plugin is installed.

Warning: Division by zero in /srv/www/dullahan/web/app/plugins/query-monitor/collectors/cache.php on line 70
Warning: Cannot modify header information - headers already sent by (output started at /srv/www/.../web/app/plugins/query-monitor/collectors/cache.php:70) in /srv/www/.../web/app/plugins/query-monitor/output/Headers.php on line 16
Biont commented 6 years ago

Thanks for the report! I'll take a look asap

Biont commented 6 years ago

@thefrosty I'm sorry it took so long to look at this. I cannot reproduce the problem right now and have never notices an error like this in projects where bot WP Stash and Query Monitor are active.

Query monitor basically does this:

$total = $this->data['stats']['cache_misses'] + $this->data['stats']['cache_hits'];
$this->data['cache_hit_percentage'] = ( 100 / $total ) * $this->data['stats']['cache_hits'];

(in https://github.com/johnbillion/query-monitor/blob/32ac837b8737b8e6dd965e72ea4ad905d4548603/collectors/cache.php#L69-L70)

So you'll get a division by zero if bot cache_misses and cache_hits evaluate to 0. QM grabs these values directly from the $wp_object_cache object here https://github.com/johnbillion/query-monitor/blob/32ac837b8737b8e6dd965e72ea4ad905d4548603/collectors/cache.php#L24-L28

So while I would appreciate if QM could guard itself against division by zero in that spot, there are definetely things we can do here, namely implementing those 2 public variables. That would not only fix the errors you're seeing, but also make QM return useful information

Biont commented 6 years ago

@thefrosty If you're still following, can you check the master branch if it fixes the issue for you? I will happily create a new release then

Biont commented 6 years ago

Closed due to lack of activity. I'll just assume my changes fixed the issue as intended