Plugin Directory

Changeset 2202032


Ignore:
Timestamp:
11/27/2019 01:58:07 PM (6 years ago)
Author:
rossigee
Message:

Bump to version 0.4.0.

Location:
web-request-metrics/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • web-request-metrics/trunk/readme.txt

    r2187003 r2202032  
    55* Requires at least: 4.7.2
    66* Tested up to: 5.3.0
    7 * Stable tag: 0.3.0
     7* Stable tag: 0.4.0
    88* License: GPLv2
    99
     
    3434
    3535== Changelog ==
     36
     37= 0.4.0 =
     38
     39* Perform HTTP requests in parallel.
    3640
    3741= 0.3.0 =
  • web-request-metrics/trunk/web-request-metrics.php

    r2187003 r2202032  
    55Plugin URI: https://wordpress.org/plugins/web-request-metrics
    66Description: Plugin to measure the HTTP connection metrics for key pages on your site
    7 Version: 0.3.0
     7Version: 0.4.0
    88Author: Ross Golder <ross@golder.org>
    99Author URI: http://www.golder.org/
     
    1313require_once(dirname(__FILE__) . "/web-request-metrics-options.php");
    1414
    15 function metrics_fetch_stats($uri) {
     15function metrics_curl_handle($uri) {
    1616  $url = get_site_url().$uri;
    1717  $ch = curl_init($url);
    1818  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     19  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    1920  curl_exec($ch);
    20   $stats = curl_getinfo($ch);
    21   curl_close($ch);
    22 
    23   return $stats;
     21  return $ch;
    2422}
    2523
     
    6159    }
    6260    array_push($tagstrs, "uri=\"".$uri."\"");
    63     echo $id."{".join(", ",$tagstrs)."} ".$value."\n";
     61    echo $id."{".join(",",$tagstrs)."} ".$value."\n";
    6462  }
    6563
     
    7068  global $uris_to_check;
    7169
     70  // If basic auth configured, apply it
    7271  $auth_username = get_option("metrics_auth_username");
    7372  $auth_password = get_option("metrics_auth_password");
     
    8382  }
    8483
     84  // Create array of curl handles, one per URI to fetch
    8585  $uris_to_check_opt = get_option("metrics_uris_to_check");
    8686  $uris_to_check = explode("\n", $uris_to_check_opt);
    87   $stats = array();
     87  $chs = array();
     88  $mh = curl_multi_init();
    8889  foreach($uris_to_check as $uri) {
    8990    $uri = rtrim($uri);
     
    9192      continue;
    9293    }
    93 
    94     $stats[$uri] = metrics_fetch_stats($uri);
     94    $chs[$uri] = metrics_curl_handle($uri);
     95    curl_multi_add_handle($mh, $chs[$uri]);
    9596  }
    9697
     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
    97113  if(count($stats) < 1) {
    98114    // Nothing to see here, move along.
     
    100116    exit(0);
    101117  }
    102 
    103   $site =
    104   $variant = get_option("metrics_variant");
    105118
    106119  header("Content-Type: text/plain");
Note: See TracChangeset for help on using the changeset viewer.