You are here

function perfmon_test_server_configuration in Performance monitor 8

Same name and namespace in other branches
  1. 7 perfmon.inc \perfmon_test_server_configuration()

Test configuration.

1 string reference to 'perfmon_test_server_configuration'
_perfmon_performance_tests in ./perfmon.module
Core Perfmon checks.

File

./perfmon.module, line 116
Stand-alone perfmon test system.

Code

function perfmon_test_server_configuration() {
  global $_SESSION;
  global $base_url;
  $domain = $_SERVER['SERVER_NAME'];
  $port = $_SERVER['SERVER_PORT'];
  $request_uri = '/perfmon.test.php';
  $url = $base_url . $request_uri;
  $executeCount = 50;
  $executeTime = 0;
  $count = 10;
  $curl_arr = array();
  $master = curl_multi_init();
  $cookiestr = "";
  foreach ($_COOKIE as $key => $value) {
    $cookiestr = $cookiestr . $key . "=" . $value . "; ";
  }
  for ($k = 0; $k < $executeCount; $k++) {
    for ($i = 0; $i < $count; $i++) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
      curl_setopt($ch, CURLOPT_COOKIE, $cookiestr);
      curl_setopt($ch, CURLOPT_PORT, $port);
      curl_setopt($ch, CURLOPT_MAXREDIRS, 0);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $curl_arr[$i] = $ch;
      curl_multi_add_handle($master, $curl_arr[$i]);
    }
    do {
      curl_multi_exec($master, $running);
    } while ($running > 0);
    for ($i = 0; $i < $count; $i++) {
      $info = curl_getinfo($curl_arr[$i]);
      $executeTime += $info['starttransfer_time'] - $info['pretransfer_time'];
      curl_multi_remove_handle($master, $curl_arr[$i]);
      curl_close($curl_arr[$i]);
    }
    sleep(2);
  }
  return array(
    'result' => round(1 / ($executeTime / $executeCount / $count), 0),
    'value' => '0',
  );
}