Compare commits

...

6 commits

Author SHA1 Message Date
copilot-swe-agent[bot]
64c6426680 Handle preempted HTTP requests by resetting properties
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
2025-11-10 21:18:43 +00:00
Pascal Birchler
dbbb4f1387
Update src/Profiler.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-10 22:16:33 +01:00
Pascal Birchler
a31e12b841
Update src/Profiler.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-10 22:16:26 +01:00
copilot-swe-agent[bot]
721c27a747 Add HTTP mocking to test to avoid real requests
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
2025-11-10 21:04:30 +00:00
copilot-swe-agent[bot]
9ae69612e9 Improve test with mu-plugin making HTTP requests
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
2025-11-10 20:58:50 +00:00
Pascal Birchler
49258a1e09
Lint fixes 2025-11-07 15:32:15 +01:00
2 changed files with 33 additions and 14 deletions

View file

@ -2,23 +2,37 @@ 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

When I run `wp profile requests --fields=method,url,status,time`
Then STDOUT should contain:
Hello world
"""
method
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:
"""
<?php
add_action( 'muplugins_loaded', function() {
wp_remote_get( 'https://www.apple.com/' );
wp_remote_post( 'https://www.example.com/', array( 'body' => 'test' ) );
});
"""

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

View file

@ -391,10 +391,15 @@ 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,
'method' => isset( $parsed_args['method'] ) ? $parsed_args['method'] : 'GET',
'method' => ( is_array( $parsed_args ) && isset( $parsed_args['method'] ) ) ? $parsed_args['method'] : 'GET',
);
}

@ -421,7 +426,7 @@ class Profiler {
$status = $response['response']['code'];
}

$logger = new Logger(
$logger = new Logger(
array(
'method' => $this->request_args['method'],
'url' => $this->request_args['url'],