Created
June 9, 2025 20:00
-
-
Save misu200/70c0f4cc1eac7f8b2937fb4252466b02 to your computer and use it in GitHub Desktop.
fire-and-forget curl working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Usage: wp eval-file test-curl-post.php [blog_id] | |
| require_once( dirname( __FILE__ ) . '/wp-load.php' ); | |
| $blog_id = 7; // HU | |
| $output = ''; | |
| if ( is_multisite() ) { | |
| switch_to_blog( $blog_id ); | |
| $output = "Testing on Blog ID: " . get_current_blog_id() . PHP_EOL; | |
| $output .= "Site URL: " . site_url() . PHP_EOL; | |
| } | |
| $url = site_url('wp-admin/admin-ajax.php?action=task_runner_preload-urls'); | |
| // cURL setup | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_HEADER, true); // We'll parse the header for HTTP code | |
| curl_setopt($ch, CURLOPT_TIMEOUT_MS, 50); // 0.01 seconds | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
| curl_setopt($ch, CURLOPT_NOBODY, false); | |
| curl_setopt($ch, CURLOPT_USERAGENT, "CustomSG24"); | |
| curl_setopt( $ch, CURLOPT_NOSIGNAL, 1 ); | |
| $start = microtime(true); | |
| $response = curl_exec($ch); | |
| $end = microtime(true); | |
| $exec_time = $end - $start; | |
| // Separate header and body | |
| $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | |
| $header = substr($response, 0, $header_size); | |
| $body = substr($response, $header_size); | |
| // Get HTTP status code | |
| $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
| curl_close($ch); | |
| $output .= "AJAX2 URL: $url" . PHP_EOL; | |
| $output .= "HTTP Status: " . $http_code . PHP_EOL; | |
| $output .= "Execution Time: " . round($exec_time, 4) . " seconds" . PHP_EOL; | |
| $output .= "Response Body (truncated):" . PHP_EOL; | |
| $output .= substr($body, 0, 500) . PHP_EOL; | |
| echo '<pre>' . htmlspecialchars($output) . '</pre>'; | |
| if ( is_multisite() ) { | |
| restore_current_blog(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment