Skip to content

Instantly share code, notes, and snippets.

@misu200
Created June 8, 2025 18:59
Show Gist options
  • Select an option

  • Save misu200/7bc269af5dbf8b755059ad5822a7a970 to your computer and use it in GitHub Desktop.

Select an option

Save misu200/7bc269af5dbf8b755059ad5822a7a970 to your computer and use it in GitHub Desktop.
wp_remote_post speed test
<?php
// Usage: wp eval-file test-wp-remote-post.php [blog_id]
// Get the blog ID from command line arguments (default to 1 if not provided)
require_once( dirname( __FILE__ ) . '/wp-load.php' );
//$url = site_url('wp-admin/admin-ajax.php?action=task_runner_preload-urls');
$url = "https://ipify.org";
$args = [
'timeout' => 0.1,
'blocking' => false,
'sslverify' => false,
];
$start = microtime(true);
$response = wp_remote_post($url, $args);
$end = microtime(true);
$exec_time = $end - $start;
$output .= "AJAX URL: $url" . PHP_EOL;
$output .= "HTTP Status: " . wp_remote_retrieve_response_code($response) . PHP_EOL;
$output .= "Execution Time: " . round($exec_time, 4) . " seconds" . PHP_EOL;
$output .= "Response Body (truncated):" . PHP_EOL;
$output .= substr(wp_remote_retrieve_body($response), 0, 500) . PHP_EOL;
echo '<pre>' . htmlspecialchars($output) . '</pre>';
@westonruter
Copy link

Note: If using wp eval-file there's no need for this line:

require_once( dirname( __FILE__ ) . '/wp-load.php' );

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