Skip to content

Conversation

Copy link

Copilot AI commented Nov 7, 2025

Implements wp profile requests to display all HTTP requests made during WordPress load, showing method, URL, status code, and execution time for each request.

Changes

Command.php

  • Added requests() method with standard profiling options (--url, --fields, --format, --order, --orderby)
  • Displays fields: method, url, status, time

Profiler.php

  • Added $request_start_time and $request_args properties to track individual requests
  • Enhanced wp_request_begin() to capture request details (URL, method) when type='request'
  • Enhanced wp_request_end() to create Logger entries with timing and status from response
  • Updated hook parameters to match WordPress signatures ($preempt, $parsed_args, $url for pre_http_request; $response, $context, $class, $parsed_args, $url for http_api_debug)
  • Skip 'all' hook registration when profiling requests to avoid overhead
  • Added proper null checks for $parsed_args to prevent PHP warnings
  • Reset tracking properties at the start of each request to handle preempted requests (where pre_http_request filter returns early and http_api_debug doesn't fire)

composer.json

  • Registered profile requests command

Tests

  • Added features/profile-requests.feature with test scenarios including a mu-plugin that makes HTTP requests with HTTP response mocking to prevent actual external requests
  • Updated features/profile.feature usage output

Example

$ wp profile requests --fields=method,url,status,time
+-----------+----------------------------+--------+---------+
| method    | url                        | status | time    |
+-----------+----------------------------+--------+---------+
| GET       | https://api.example.com    | 200    | 0.2341s |
| POST      | https://api.example.com    | 201    | 0.1653s |
+-----------+----------------------------+--------+---------+
| total (2) |                            |        | 0.3994s |
+-----------+----------------------------+--------+---------+

Fixes #129

Original prompt

This section details on the original issue you should resolve

<issue_title>Introduce wp profile requests</issue_title>
<issue_description>It would be helpful to be able to see all requests and how much time they're taking.</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber The idea is to create a `wp profile requests` command that would minor execution time, etc. for all HTTP requests made during the WordPress load process.

Here's where we're already hooking into the HTTP request process to observe timing:

WP_CLI::add_wp_hook( 'pre_http_request', array( $this, 'wp_request_begin' ) );
WP_CLI::add_wp_hook( 'http_api_debug', array( $this, 'wp_request_end' ) );
</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 7, 2025 12:23
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add wp profile requests command for monitoring HTTP request timing Add wp profile requests command to monitor HTTP requests Nov 7, 2025
Copilot AI requested a review from swissspidy November 7, 2025 12:33
Copilot finished work on behalf of swissspidy November 7, 2025 12:33
@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

❌ Patch coverage is 52.38095% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Profiler.php 31.03% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI requested a review from swissspidy November 10, 2025 21:01
Copilot finished work on behalf of swissspidy November 10, 2025 21:01
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot finished work on behalf of swissspidy November 10, 2025 21:06
@swissspidy swissspidy requested a review from Copilot November 10, 2025 21:12
Copilot finished reviewing on behalf of swissspidy November 10, 2025 21:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new wp profile requests command to monitor and display HTTP requests made during WordPress load, including their method, URL, status code, and execution time.

Key changes:

  • Added requests() method to Command.php with standard profiling options
  • Enhanced Profiler.php to capture and log individual HTTP request details
  • Registered the new command in composer.json and added comprehensive test coverage

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Command.php Implements the requests subcommand with standard formatting and ordering options
src/Profiler.php Adds request tracking properties and enhances HTTP hook handlers to capture request details and timing
composer.json Registers the new profile requests command
features/profile-requests.feature Adds test scenarios for HTTP request profiling with mocked responses
features/profile.feature Updates usage documentation to include the new requests command

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

swissspidy and others added 2 commits November 10, 2025 22:16
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot finished work on behalf of swissspidy November 10, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce wp profile requests

2 participants