Skip to content

Add HTTP request logging #6044

Closed
Closed

Description

@swissspidy

Feature Request

Describe your use case and the problem you are facing

After #6036, one idea that came up is that right now there isn't any visibility into all the outgoing HTTP requests made by WP-CLI.

Such information could be really useful though for debugging and identifying slow parts of the code base.

Describe the solution you'd like

Some ideas on how the HTTP request logging could be implemented:

  • Add new bootstrap step that hooks into the http_request_options CLI hook and the pre_http_request WP hook (in \WP_CLI\Runner::setup_bootstrap_hooks perhaps?)
  • The hook would would only print a minimal debug message such as HTTP POST request to https://....
    • This would use a dedicated http debug group
  • The full request & response info could optionally be written to a log file (useful for Behat tests)
    • How could this be made opt-in?

Activity

  1. swissspidy commented on Feb 11, 2025

    @swissspidy
    MemberAuthor

    Theoretically for the http_request() function we could just add a WP_CLI::debug() line there, no need to use any hooks. But then the file saving wouldn't be feasible.

    The http_request_options hook would be more useful if we'd pass the additional args as well, i.e. $method, $url, $data, $headers

    The full request & response info could optionally be written to a log file

    Not sure what the best approach would be there, don't think we do that anywhere else.

    Assuming we only do this for tests, then this could be done in the test directory. And then using the hook makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions