mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-11-22 04:46:25 +08:00
Compare commits
6 commits
8418ad2d97
...
64c6426680
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64c6426680 | ||
|
|
dbbb4f1387 | ||
|
|
a31e12b841 | ||
|
|
721c27a747 | ||
|
|
9ae69612e9 | ||
|
|
49258a1e09 |
2 changed files with 33 additions and 14 deletions
|
|
@ -2,23 +2,37 @@ Feature: Profile HTTP requests
|
||||||
|
|
||||||
Scenario: Profile HTTP requests during WordPress load
|
Scenario: Profile HTTP requests during WordPress load
|
||||||
Given a WP install
|
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`
|
Hello world
|
||||||
Then STDOUT should contain:
|
|
||||||
"""
|
"""
|
||||||
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:
|
And STDOUT should contain:
|
||||||
"""
|
"""
|
||||||
url
|
total (2)
|
||||||
"""
|
|
||||||
And STDOUT should contain:
|
|
||||||
"""
|
|
||||||
status
|
|
||||||
"""
|
|
||||||
And STDOUT should contain:
|
|
||||||
"""
|
|
||||||
time
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Scenario: Profile shows no requests when none are made
|
Scenario: Profile shows no requests when none are made
|
||||||
|
|
|
||||||
|
|
@ -391,10 +391,15 @@ class Profiler {
|
||||||
|
|
||||||
// For request profiling, capture details of each HTTP request
|
// For request profiling, capture details of each HTTP request
|
||||||
if ( 'request' === $this->type ) {
|
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_start_time = microtime( true );
|
||||||
$this->request_args = array(
|
$this->request_args = array(
|
||||||
'url' => $url,
|
'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'];
|
$status = $response['response']['code'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger = new Logger(
|
$logger = new Logger(
|
||||||
array(
|
array(
|
||||||
'method' => $this->request_args['method'],
|
'method' => $this->request_args['method'],
|
||||||
'url' => $this->request_args['url'],
|
'url' => $this->request_args['url'],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue