johnbillion / query-monitor

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

PHP Fatal Error #841

Closed hogash closed 7 months ago

hogash commented 9 months ago

Hey!

I'm sometimes getting this error below, however I'm not entirely sure when. I believe when I'm inside Customizer.

PHP Fatal error:  Uncaught TypeError: parse_url(): Argument #1 ($url) must be of type string, bool given in /../wp-content/plugins/query-monitor/collectors/http.php:374
Stack trace:
#0 /../wp-content/plugins/query-monitor/collectors/http.php(374): parse_url(false, 1)
#1 /../wp-content/plugins/query-monitor/classes/Collectors.php(84): QM_Collector_HTTP->process()
#2 /../wp-content/plugins/query-monitor/classes/Dispatcher.php(108): QM_Collectors->process()
#3 /../wp-content/plugins/query-monitor/dispatchers/Html.php(352): QM_Dispatcher->get_outputters('html')
#4 /../wp-content/plugins/query-monitor/dispatchers/Html.php(316): QM_Dispatcher_Html->before_output()
#5 /../wp-includes/class-wp-hook.php(324): QM_Dispatcher_Html->dispatch('')
#6 /../wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#7 /../wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#8 /../wp-includes/load.php(1260): do_action('shutdown')
#9 [internal function]: shutdown_action_hook()
#10 {main}
  thrown in /../wp-content/plugins/query-monitor/collectors/http.php on line 374

Looking at the code, I believe instead of..

$host = (string) parse_url( $request['url'], PHP_URL_HOST );

It should be..

$host = parse_url( (string) $request['url'], PHP_URL_HOST );

crstauf commented 9 months ago

I suspect both may be needed, as parse_url() may return false.

johnbillion commented 9 months ago

What's causing the $url parameter to be false?

hogash commented 9 months ago

What's causing the $url parameter to be false?

I don't know I didn't noticed a specific pattern except sometimes when visiting Customizer (although I'm not entirely sure).

I just added this below to see the full $request and backtrace. Will keep you updated.

if( ! is_string($request['url']) ){
    error_log(var_export( [
        $request,
        wp_debug_backtrace_summary(),
    ], true));
}
johnbillion commented 7 months ago

Did you find anything from this @hogash ?

hogash commented 7 months ago

Did you find anything from this @hogash ?

No, I didn't. Let's close the issue for the moment and get back in case that error returns. Thanks!