From 49258a1e0944cad6c61bc0b9a9e9bcb22d7561c6 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 7 Nov 2025 15:32:15 +0100 Subject: [PATCH 1/6] Lint fixes --- src/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Profiler.php b/src/Profiler.php index c572bdb..07f4da2 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -404,7 +404,7 @@ class Profiler { /** * Profiling request time for any active Loggers */ - public function wp_request_end( $response = null, $context = null, $class = null, $parsed_args = null, $url = null ) { + public function wp_request_end( $response = null ) { foreach ( Logger::$active_loggers as $logger ) { $logger->stop_request_timer(); } @@ -421,7 +421,7 @@ class Profiler { $status = $response['response']['code']; } - $logger = new Logger( + $logger = new Logger( array( 'method' => $this->request_args['method'], 'url' => $this->request_args['url'], From 9ae69612e9e7e9a7683735e5523dc7d5335d53a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 20:58:50 +0000 Subject: [PATCH 2/6] Improve test with mu-plugin making HTTP requests Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/profile-requests.feature | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/features/profile-requests.feature b/features/profile-requests.feature index 3f85d0f..de897b1 100644 --- a/features/profile-requests.feature +++ b/features/profile-requests.feature @@ -2,23 +2,23 @@ Feature: Profile HTTP requests Scenario: Profile HTTP requests during WordPress load Given a WP install + And a wp-content/mu-plugins/http-requests.php file: + """ + 'test' ) ); + }); + """ - When I run `wp profile requests --fields=method,url,status,time` - Then STDOUT should contain: - """ - method - """ + When I run `wp profile requests --fields=method,url` + Then STDOUT should be a table containing rows: + | method | url | + | GET | https://www.apple.com/ | + | POST | https://www.example.com/ | And STDOUT should contain: """ - url - """ - And STDOUT should contain: - """ - status - """ - And STDOUT should contain: - """ - time + total (2) """ Scenario: Profile shows no requests when none are made From 721c27a7471af9f7fba6794de1b93bb2213932a0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 21:04:30 +0000 Subject: [PATCH 3/6] Add HTTP mocking to test to avoid real requests Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/profile-requests.feature | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/features/profile-requests.feature b/features/profile-requests.feature index de897b1..50ddd1f 100644 --- a/features/profile-requests.feature +++ b/features/profile-requests.feature @@ -2,6 +2,20 @@ Feature: Profile HTTP requests Scenario: Profile HTTP requests during WordPress load Given a WP install + And that HTTP requests to https://www.apple.com/ will respond with: + """ + HTTP/1.1 200 + Content-Type: text/plain + + Hello world + """ + And that HTTP requests to https://www.example.com/ will respond with: + """ + HTTP/1.1 201 + Content-Type: application/json + + {"status":"created"} + """ And a wp-content/mu-plugins/http-requests.php file: """ Date: Mon, 10 Nov 2025 22:16:26 +0100 Subject: [PATCH 4/6] Update src/Profiler.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Profiler.php b/src/Profiler.php index 07f4da2..fec11a3 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -404,7 +404,7 @@ class Profiler { /** * Profiling request time for any active Loggers */ - public function wp_request_end( $response = null ) { + public function wp_request_end( $response = null, $context = null, $class = null, $parsed_args = null, $url = null ) { foreach ( Logger::$active_loggers as $logger ) { $logger->stop_request_timer(); } From dbbb4f138775025c25844ae9229bc829cb85c103 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 10 Nov 2025 22:16:33 +0100 Subject: [PATCH 5/6] Update src/Profiler.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Profiler.php b/src/Profiler.php index fec11a3..3db7b89 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -394,7 +394,7 @@ class Profiler { $this->request_start_time = microtime( true ); $this->request_args = array( 'url' => $url, - 'method' => isset( $parsed_args['method'] ) ? $parsed_args['method'] : 'GET', + 'method' => ( is_array( $parsed_args ) && isset( $parsed_args['method'] ) ) ? $parsed_args['method'] : 'GET', ); } From 64c64266804489f8b31229a9d7fb57fefc8c6ba8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 21:18:43 +0000 Subject: [PATCH 6/6] Handle preempted HTTP requests by resetting properties Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Profiler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Profiler.php b/src/Profiler.php index 3db7b89..228d479 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -391,6 +391,11 @@ class Profiler { // For request profiling, capture details of each HTTP request if ( 'request' === $this->type ) { + // Reset properties first to handle cases where previous request was preempted + $this->request_start_time = null; + $this->request_args = null; + + // Now capture the new request details $this->request_start_time = microtime( true ); $this->request_args = array( 'url' => $url,