Changeset 2202032
- Timestamp:
- 11/27/2019 01:58:07 PM (6 years ago)
- Location:
- web-request-metrics/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
web-request-metrics.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
web-request-metrics/trunk/readme.txt
r2187003 r2202032 5 5 * Requires at least: 4.7.2 6 6 * Tested up to: 5.3.0 7 * Stable tag: 0. 3.07 * Stable tag: 0.4.0 8 8 * License: GPLv2 9 9 … … 34 34 35 35 == Changelog == 36 37 = 0.4.0 = 38 39 * Perform HTTP requests in parallel. 36 40 37 41 = 0.3.0 = -
web-request-metrics/trunk/web-request-metrics.php
r2187003 r2202032 5 5 Plugin URI: https://wordpress.org/plugins/web-request-metrics 6 6 Description: Plugin to measure the HTTP connection metrics for key pages on your site 7 Version: 0. 3.07 Version: 0.4.0 8 8 Author: Ross Golder <ross@golder.org> 9 9 Author URI: http://www.golder.org/ … … 13 13 require_once(dirname(__FILE__) . "/web-request-metrics-options.php"); 14 14 15 function metrics_ fetch_stats($uri) {15 function metrics_curl_handle($uri) { 16 16 $url = get_site_url().$uri; 17 17 $ch = curl_init($url); 18 18 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 19 curl_setopt($ch, CURLOPT_TIMEOUT, 30); 19 20 curl_exec($ch); 20 $stats = curl_getinfo($ch); 21 curl_close($ch); 22 23 return $stats; 21 return $ch; 24 22 } 25 23 … … 61 59 } 62 60 array_push($tagstrs, "uri=\"".$uri."\""); 63 echo $id."{".join(", ",$tagstrs)."} ".$value."\n";61 echo $id."{".join(",",$tagstrs)."} ".$value."\n"; 64 62 } 65 63 … … 70 68 global $uris_to_check; 71 69 70 // If basic auth configured, apply it 72 71 $auth_username = get_option("metrics_auth_username"); 73 72 $auth_password = get_option("metrics_auth_password"); … … 83 82 } 84 83 84 // Create array of curl handles, one per URI to fetch 85 85 $uris_to_check_opt = get_option("metrics_uris_to_check"); 86 86 $uris_to_check = explode("\n", $uris_to_check_opt); 87 $stats = array(); 87 $chs = array(); 88 $mh = curl_multi_init(); 88 89 foreach($uris_to_check as $uri) { 89 90 $uri = rtrim($uri); … … 91 92 continue; 92 93 } 93 94 $stats[$uri] = metrics_fetch_stats($uri);94 $chs[$uri] = metrics_curl_handle($uri); 95 curl_multi_add_handle($mh, $chs[$uri]); 95 96 } 96 97 98 // Process the curl requests in parallel 99 $running = null; 100 do { 101 curl_multi_exec($mh, $running); 102 } while ($running); 103 104 // Close curl handles and extract results 105 $stats = array(); 106 foreach($chs as $uri => $ch) { 107 curl_multi_remove_handle($mh, $ch); 108 $stats[$uri] = curl_getinfo($ch); 109 } 110 curl_multi_close($mh); 111 112 // Extract stats from each 97 113 if(count($stats) < 1) { 98 114 // Nothing to see here, move along. … … 100 116 exit(0); 101 117 } 102 103 $site =104 $variant = get_option("metrics_variant");105 118 106 119 header("Content-Type: text/plain");
Note: See TracChangeset
for help on using the changeset viewer.