/**
* Gather all of the data for a given test and return it as an array
* 
* @param mixed $id
*/
function GetTestResult($id)
{
    global $url;
    global $median_metric;
    $testPath = './' . GetTestPath($id);
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http';
    $host = $_SERVER['HTTP_HOST'];
    $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $path = substr($testPath, 1);
    $pageData = loadAllPageData($testPath);
    $stats = array(0 => array(), 1 => array());
    $pageStats = calculatePageStats($pageData, $stats[0], $stats[1]);
    if (!strlen($url)) {
        $url = $pageData[1][0]['URL'];
    }
    $testInfo = GetTestInfo($id);
    if (is_file("{$testPath}/testinfo.ini")) {
        $test = parse_ini_file("{$testPath}/testinfo.ini", true);
    }
    $fvOnly = false;
    if (!count($stats[1])) {
        $fvOnly = true;
    }
    $cacheLabels = array('firstView', 'repeatView');
    // summary information
    $ret = array('id' => $id, 'url' => $url, 'summary' => "{$protocol}://{$host}{$uri}/results.php?test={$id}");
    $runs = max(array_keys($pageData));
    if (isset($testInfo)) {
        if (array_key_exists('url', $testInfo) && strlen($testInfo['url'])) {
            $ret['testUrl'] = $testInfo['url'];
        }
        if (array_key_exists('location', $testInfo) && strlen($testInfo['location'])) {
            $locstring = $testInfo['location'];
            if (array_key_exists('browser', $testInfo) && strlen($testInfo['browser'])) {
                $locstring .= ':' . $testInfo['browser'];
            }
            $ret['location'] = $locstring;
        }
        if (isset($test) && array_key_exists('test', $test) && is_array($test['test']) && array_key_exists('location', $test['test']) && strlen($test['test']['location'])) {
            $ret['from'] = $test['test']['location'];
        }
        if (array_key_exists('connectivity', $testInfo) && strlen($testInfo['connectivity'])) {
            $ret['connectivity'] = $testInfo['connectivity'];
        }
        if (array_key_exists('bwIn', $testInfo)) {
            $ret['bwDown'] = $testInfo['bwIn'];
        }
        if (array_key_exists('bwOut', $testInfo)) {
            $ret['bwUp'] = $testInfo['bwOut'];
        }
        if (array_key_exists('latency', $testInfo)) {
            $ret['latency'] = $testInfo['latency'];
        }
        if (array_key_exists('plr', $testInfo)) {
            $ret['plr'] = $testInfo['plr'];
        }
        if (array_key_exists('label', $testInfo) && strlen($testInfo['label'])) {
            $ret['label'] = $testInfo['label'];
        }
        if (array_key_exists('completed', $testInfo)) {
            $ret['completed'] = $testInfo['completed'];
        }
        if (array_key_exists('tester', $testInfo) && strlen($testInfo['tester'])) {
            $ret['tester'] = $testInfo['tester'];
        }
        if (array_key_exists('testerDNS', $testInfo) && strlen($testInfo['testerDNS'])) {
            $ret['testerDNS'] = $testInfo['testerDNS'];
        }
        if (array_key_exists('runs', $testInfo) && $testInfo['runs']) {
            $runs = $testInfo['runs'];
        }
        if (array_key_exists('fvonly', $testInfo)) {
            $fvOnly = $testInfo['fvonly'] ? true : false;
        }
    }
    $cachedMax = 0;
    if (!$fvOnly) {
        $cachedMax = 1;
    }
    $ret['runs'] = $runs;
    $ret['fvonly'] = $fvOnly;
    $ret['successfulFVRuns'] = CountSuccessfulTests($pageData, 0);
    if (!$fvOnly) {
        $ret['successfulRVRuns'] = CountSuccessfulTests($pageData, 1);
    }
    // average
    // check if removing average
    $addAverage = 1;
    if (isset($_GET['average'])) {
        if ($_GET['average'] == 0) {
            $addAverage = 0;
        }
    }
    // add average
    if ($addAverage == 1) {
        $ret['average'] = array();
        for ($cached = 0; $cached <= $cachedMax; $cached++) {
            $label = $cacheLabels[$cached];
            $ret['average'][$label] = $stats[$cached];
        }
    }
    // standard deviation
    // check if removing standard deviation
    $addStandard = 1;
    if (isset($_GET['standard'])) {
        if ($_GET['standard'] == 0) {
            $addStandard = 0;
        }
    }
    // add standard deviation
    if ($addStandard == 1) {
        $ret['standardDeviation'] = array();
        for ($cached = 0; $cached <= $cachedMax; $cached++) {
            $label = $cacheLabels[$cached];
            $ret['standardDeviation'][$label] = array();
            foreach ($stats[$cached] as $key => $val) {
                $ret['standardDeviation'][$label][$key] = PageDataStandardDeviation($pageData, $key, $cached);
            }
        }
    }
    // median
    // check if removing median
    $addMedian = 1;
    if (isset($_GET['median'])) {
        if ($_GET['median'] == 0) {
            $addMedian = 0;
        }
    }
    // add median
    if ($addMedian == 1) {
        $ret['median'] = array();
        for ($cached = 0; $cached <= $cachedMax; $cached++) {
            $label = $cacheLabels[$cached];
            $medianRun = GetMedianRun($pageData, $cached, $median_metric);
            if (array_key_exists($medianRun, $pageData)) {
                $ret['median'][$label] = GetSingleRunData($id, $testPath, $medianRun, $cached, $pageData, $testInfo);
            }
        }
    }
    // runs
    // check if removing runs
    $addRuns = 1;
    if (isset($_GET['runs'])) {
        if ($_GET['runs'] == 0) {
            $addRuns = 0;
        }
    }
    // add runs
    if ($addRuns == 1) {
        $ret['runs'] = array();
        for ($run = 1; $run <= $runs; $run++) {
            $ret['runs'][$run] = array();
            for ($cached = 0; $cached <= $cachedMax; $cached++) {
                $label = $cacheLabels[$cached];
                $ret['runs'][$run][$label] = GetSingleRunData($id, $testPath, $run, $cached, $pageData, $testInfo);
            }
        }
    }
    ArchiveApi($id);
    return $ret;
}
Esempio n. 2
0
                 if (array_key_exists('requests', $_REQUEST) && $_REQUEST['requests'] != 'median') {
                     xmlRequests($id, $testPath, $i, 1);
                 }
                 StatusMessages($id, $testPath, $i, 1);
                 ConsoleLog($id, $testPath, $i, 1);
                 echo "</repeatView>\n";
             }
         }
         echo "</run>\n";
     }
     echo "</data>\n";
     echo "</response>\n";
     $msElapsed = number_format(microtime(true) - $msStart, 3);
     $msElapsedLoad = number_format($msLoad - $msStart, 3);
     logMsg("xmlResult ({$id}): {$msElapsed}s ({$msElapsedLoad}s to load page data)");
     ArchiveApi($id);
 } else {
     header('Content-type: text/xml');
     header("Cache-Control: no-cache, must-revalidate");
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     echo "<response>\n";
     if (strlen($_REQUEST['r'])) {
         echo "<requestId>{$_REQUEST['r']}</requestId>\n";
     }
     // see if it was a valid test
     if ($test['test']['runs']) {
         if (isset($test['test']['startTime'])) {
             echo "<statusCode>101</statusCode>\n";
             echo "<statusText>Test Started</statusText>\n";
             echo "<data>\n";