Example #1
0
 if (!strlen($url)) {
     $url = $pageData[1][0]['URL'];
 }
 header('Content-type: text/xml');
 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 echo "<response>\n";
 echo "<statusCode>200</statusCode>\n";
 echo "<statusText>Ok</statusText>\n";
 if (array_key_exists('r', $_REQUEST) && strlen($_REQUEST['r'])) {
     echo "<requestId>{$_REQUEST['r']}</requestId>\n";
 }
 echo "<data>\n";
 // spit out the calculated averages
 $fv = null;
 $rv = null;
 $pageStats = calculatePageStats($pageData, $fv, $rv);
 echo "<testId>{$id}</testId>\n";
 if (FRIENDLY_URLS) {
     echo "<summary>http://{$host}{$uri}/result/{$id}/</summary>\n";
 } else {
     echo "<summary>http://{$host}{$uri}/results.php?test={$id}</summary>\n";
 }
 if (isset($test['testinfo'])) {
     if (@strlen($test['testinfo']['url'])) {
         echo "<testUrl>" . xml_entities($test['testinfo']['url']) . "</testUrl>\n";
     }
     if (@strlen($test['testinfo']['location'])) {
         $locstring = $test['testinfo']['location'];
         if (@strlen($test['testinfo']['browser'])) {
             $locstring .= ':' . $test['testinfo']['browser'];
         }
/**
* 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;
}
Example #3
0
/**
* Send a mail notification to the user
* 
* @param mixed $mailto
* @param mixed $id
* @param mixed $testPath
*/
function notify($mailto, $from, $id, $testPath, $host)
{
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: {$from}\r\n";
    $headers .= "Reply-To: {$from}";
    $url;
    if (is_file("{$testPath}/url.txt")) {
        $url = htmlspecialchars(file_get_contents("{$testPath}/url.txt"));
    }
    $shorturl = substr($url, 0, 40);
    if (strlen($url) > 40) {
        $shorturl .= '...';
    }
    $subject = "Test results for {$shorturl}";
    if (!isset($host)) {
        $host = $_SERVER['HTTP_HOST'];
    }
    // calculate the results
    require_once 'page_data.inc';
    $pageData = loadAllPageData($testPath);
    $fv = null;
    $rv = null;
    $pageStats = calculatePageStats($pageData, $fv, $rv);
    if (isset($fv)) {
        $load = number_format($fv['loadTime'] / 1000.0, 3);
        $render = number_format($fv['render'] / 1000.0, 3);
        $requests = number_format($fv['requests'], 0);
        $bytes = number_format($fv['bytesIn'] / 1024, 0);
        $result = "http://{$host}/result/{$id}";
        // capture the optimization report
        require_once '../optimization.inc';
        ob_start();
        dumpOptimizationReport($testPath, 1, 0);
        $optimization = ob_get_contents();
        ob_end_clean();
        // build the message body
        $body = "<html>\r\n            <head>\r\n                <title>{$subject}</title>\r\n                <style type=\"text/css\">\r\n                    .indented1 {padding-left: 40pt;}\r\n                    .indented2 {padding-left: 80pt;}\r\n                </style>\r\n            </head>\r\n            <body>\r\n            <p>The full test results for <a href=\"{$url}\">{$url}</a> are now <a href=\"{$result}/\">available</a>.</p>\r\n            <p>The page loaded in <b>{$load} seconds</b> with the user first seeing something on the page after <b>{$render} seconds</b>.  To download \r\n            the page required <b>{$requests} requests</b> and <b>{$bytes} KB</b>.</p>\r\n            <p>Here is what the page looked like when it loaded (click the image for a larger view):<br><a href=\"{$result}/1/screen_shot/\"><img src=\"{$result}/1_screen_thumb.jpg\"></a></p>\r\n            <h3>Here are the things on the page that could use improving:</h3>\r\n            {$optimization}\r\n            </body>\r\n        </html>";
        // send the actual mail
        mail($mailto, $subject, $body, $headers);
    }
}