johnbillion / query-monitor

The developer tools panel for WordPress
https://querymonitor.com
GNU General Public License v2.0
1.59k stars 208 forks source link

Possible `502 Bad Gateway` errors with PHP 8.2 #813

Closed pyksid closed 1 year ago

pyksid commented 1 year ago

When migrating to PHP 8.2, there may be many PHP deprecated messages (70+), for example:

Deprecated: Creation of dynamic property CF\WordPress\DataStore::$logger is deprecated in /var/www/html/web/app/plugins/cloudflare/src/WordPress/DataStore.php on line 23

Deprecated: Creation of dynamic property EIO_Backup::$relative_home_url is deprecated in /var/www/html/web/app/plugins/ewww-image-optimizer/classes/class-eio-base.php on line 98

Deprecated: Creation of dynamic property SimpleCommentsLogger::$db_table is deprecated in /var/www/html/web/app/plugins/simple-history/loggers/SimpleLogger.php on line 68

[...]

As Query Monitor catches all these PHP deprecated messages with filter_wp_redirect() (dispatchers/Redirect.php) and output them in headers throught header( sprintf( 'X-QM-%s-%s: %s', $id, $key, $value ) ); (output/Headers.php), the final headers can be too big for the web server.

With nginx, I had this error with 502 Bad Gateway when saving posts or doing others actions:

upstream sent too big header while reading response header from upstream

To fix the problem, I had to disable Query Monitor output headers:

add_filter('qm/dispatch/ajax', '__return_false');
add_filter('qm/dispatch/redirect', '__return_false');
add_filter('qm/dispatch/rest', '__return_false');

Other alternative, you can increase buffers in nginx but it's not the best solution:

fastcgi_buffers 8 32k;
fastcgi_buffer_size 32k;
fastcgi_busy_buffers_size 64k;

Maybe should we limit the number of X-QM- headers if it exceeds a certain threshold?

johnbillion commented 1 year ago

Thanks for the report. We've been discussing this in #708 so I'll close this off in favour of that ticket. Cheers!