Esempio n. 1
0
function ProcessHARData($parsedHar, $testPath, $harIsFromSinglePageLoad)
{
    // Sort the entries by start time. This is done across runs, but
    // since each of them references its own page it shouldn't matter
    $sortedEntries;
    foreach ($parsedHar['log']['entries'] as $entrycount => $entry) {
        // We use the textual start date as key, which should work fine
        // for ISO dates.
        $start = $entry['startedDateTime'];
        $sortedEntries[$start . "-" . $entrycount] = $entry;
    }
    ksort($sortedEntries);
    // HAR files can hold multiple page loads.  Some sources of HAR files
    // can only hold one page load, and don't know anything about the page.
    // For example, HAR files generated from a .pcap file captured durring
    // a single page load must have only one page, and many things in a HAR
    // page record, such as the page title, can not be found.  Based on the
    // number of page records, and the argument $harIsFromSinglePageLoad,
    // check that the pages record is as expected, and generate a minimal
    // page record if nessisary.
    $numPageRecords = array_key_exists('pages', $parsedHar['log']) ? count($parsedHar['log']['pages']) : 0;
    if ($harIsFromSinglePageLoad) {
        if ($numPageRecords > 1) {
            logMalformedInput("HAR has multiple pages, but it should be from " . "a single run.");
            return;
        }
        if ($numPageRecords == 0) {
            // pcap2har will not generate any pages records when using option
            // --no-pages.  Build a fake one.  This simplfies the rest of the
            // HAR proccessing code, because it does not need to check for the
            // existance of the page record every time it tries to read page
            // info.
            CreatePageRecordInHar($parsedHar, $sortedEntries);
        }
    } else {
        // ! if ($harIsFromSinglePageLoad)
        if ($numPageRecords == 0) {
            logMalformedInput("No page records in HAR.  Expect at least one.");
            return;
        }
    }
    // Keep meta data about a page from iterating the entries
    $pageData;
    // Iterate over the page records.
    foreach ($parsedHar['log']['pages'] as $pagecount => $page) {
        $pageref = $page['id'];
        $curPageData = array();
        // Extract direct page data and save in data array
        $curPageData["url"] = $page['title'];
        $startFull = $page['startedDateTime'];
        $startFullDatePart = '';
        $startFullTimePart = '';
        if (SplitISO6801DateIntoDateAndTime($startFull, $startFullDatePart, $startFullTimePart)) {
            // into these parts.
            $curPageData["startDate"] = $startFullDatePart;
            $curPageData["startTime"] = $startFullTimePart;
            $curPageData["startFull"] = $startFull;
        } else {
            logMalformedInput("Failed to split page key 'startedDateTime' into a date and " . "a time part.  Value of key is '{$startFull}'.");
        }
        global $onRender;
        $curPageData["onRender"] = arrayLookupWithDefault('onRender', $page['pageTimings'], arrayLookupWithDefault('_onRender', $page['pageTimings'], $onRender !== null ? $onRender : UNKNOWN_TIME));
        $curPageData["docComplete"] = arrayLookupWithDefault('onContentLoad', $page['pageTimings'], UNKNOWN_TIME);
        $curPageData["fullyLoaded"] = arrayLookupWithDefault('onLoad', $page['pageTimings'], UNKNOWN_TIME);
        // TODO: Remove this patch for files missing the data.
        if ($curPageData["docComplete"] <= 0) {
            $curPageData["docComplete"] = $curPageData["fullyLoaded"];
        }
        // Agents that upload .pcap files must tell us the URL being tested,
        // because the URL is not always in the .pcap file.  If POST
        // parameter _urlUnderTest is set, use it as the URL being measured.
        global $urlUnderTest;
        $curPageDataUrl = isset($urlUnderTest) ? $urlUnderTest : $curPageData["url"];
        if (preg_match("/^https?:\\/\\/([^\\/?]+)(((?:\\/|\\?).*\$)|\$)/", $curPageDataUrl, $urlMatches)) {
            $curPageData["host"] = $urlMatches[1];
        } else {
            logMalformedInput("HAR error: Could not match host in URL " . $curPageDataUrl);
        }
        // Some clients encode the run number and cache status in the
        // page name.  Others give the information in properties on the
        // pageTimings record.  Prefer the explicit properties.  Fall
        // back to decoding the information from the name of the page
        // record.
        global $runNumber;
        global $cacheWarmed;
        global $docComplete;
        global $onFullyLoaded;
        if (array_key_exists('_runNumber', $page)) {
            $curPageData["run"] = $page['_runNumber'];
            $curPageData["cached"] = $page['_cacheWarmed'];
        } else {
            if (isset($runNumber) && isset($cacheWarmed)) {
                $curPageData["run"] = $runNumber;
                $curPageData["cached"] = $cacheWarmed;
                if (isset($docComplete) && $curPageData["docComplete"] <= 0) {
                    $curPageData["docComplete"] = $docComplete;
                }
                if (isset($onFullyLoaded) && $curPageData['fullyLoaded'] <= 0) {
                    $curPageData['fullyLoaded'] = $onFullyLoaded;
                }
            } else {
                if (preg_match("/page_(\\d+)_([01])/", $pageref, $matches)) {
                    $curPageData["run"] = $matches[1];
                    $curPageData["cached"] = $matches[2];
                } else {
                    logMalformedInput("HAR error: Could not get runs or cache " . "status, from post params, pages array " . "or page name \"{$pageref}\".");
                    // Sensible defaults:
                    $curPageData["run"] = 1;
                    $curPageData["cached"] = 0;
                }
            }
        }
        if ($curPageData["run"] <= 0) {
            logMalformedInput("HAR error: \$curPageData[\"run\"] should " . "always be positive.  Value is " . $curPageData["run"]);
        }
        $curPageData["title"] = ($curPageData["cached"] ? "Cached-" : "Cleared Cache-") . "Run_" . $curPageData["run"] . "^" . $curPageData["url"];
        // Define filename prefix
        $curPageData["runFilePrefix"] = $testPath . "/" . $curPageData["run"] . "_";
        if ($curPageData["cached"]) {
            $curPageData["runFilePrefix"] .= "Cached_";
        }
        $curPageData["runFileName"] = $curPageData["runFilePrefix"] . "IEWTR.txt";
        $curPageData["reportFileName"] = $curPageData["runFilePrefix"] . "report.txt";
        // Write the title line
        file_put_contents($curPageData["runFileName"], "Date\tTime\tEvent Name\tIP Address\tAction\tHost\tURL\tResponse Code\t" . "Time to Load (ms)\tTime to First Byte (ms)\tStart Time (ms)\tBytes Out\t" . "Bytes In\tObject Size\tCookie Size (out)\tCookie Count(out)\tExpires\t" . "Cache Control\tContent Type\tContent Encoding\tTransaction Type\tSocket ID\t" . "Document ID\tEnd Time (ms)\tDescriptor\tLab ID\tDialer ID\tConnection Type\t" . "Cached\tEvent URL\tPagetest Build\tMeasurement Type\tExperimental\tEvent GUID\t" . "Sequence Number\tCache Score\tStatic CDN Score\tGZIP Score\tCookie Score\t" . "Keep-Alive Score\tDOCTYPE Score\tMinify Score\tCombine Score\tCompression Score\t" . "ETag Score\tFlagged\tSecure\tDNS Time\tConnect Time\tSSL Time\tGzip Total Bytes\t" . "Gzip Savings\tMinify Total Bytes\tMinify Savings\tImage Total Bytes\tImage Savings\t" . "Cache Time (sec)\tReal Start Time (ms)\tFull Time to Load (ms)\tOptimization Checked\r\n");
        // Write the page line line
        file_put_contents($curPageData["runFileName"], "{$curPageData['startDate']}\t{$curPageData['startTime']}\t" . "{$curPageData['title']}\t\t\t{$curPageData['host']}\t{$curPageData['url']}\t" . "0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t\t\t\t0\t0\t0\t0\tLaunch\t-1\t0\t-1\t" . "{$curPageData['cached']}\t{$curPageData['url']}\t" . "0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t-1\t0\t0\t0\t0\t0\t0\t\t\t\t0\t0\t0\t0\t0\t0\t" . "\t0\t\t0\r\n", FILE_APPEND);
        // Write the raw data in the report (not accurate, may need to fix after)
        // TODO: Write real data
        file_put_contents($curPageData["reportFileName"], "Results for '{$curPageData['url']}':\r\n\r\n" . "Page load time: 0 seconds\r\n" . "Time to first byte: 0 seconds\r\n" . "Time to Base Page Downloaded: 0 seconds\r\n" . "Time to Start Render: 0 seconds\r\n" . "Time to Document Complete: 0 seconds\r\n" . "Time to Fully Loaded: 0 seconds\r\n" . "Bytes sent out: 0 KB\r\n" . "Bytes received: 0 KB\r\n" . "DNS Lookups: 0\r\n" . "Connections: 0\r\n" . "Requests: 0\r\n" . "   OK Requests:  0\r\n" . "   Redirects:    0\r\n" . "   Not Modified: 0\r\n" . "   Not Found:    0\r\n" . "   Other:        0\r\n" . "Base Page Response: 200\r\n" . "Request details:\r\n\r\n");
        // Start by stating the time-to-first-byte is the page load time,
        // will be updated as we iterate requests.
        $curPageData["TTFB"] = $curPageData["docComplete"];
        // Reset counters for requests
        $curPageData["bytesOut"] = 0;
        $curPageData["bytesIn"] = 0;
        $curPageData["nDnsLookups"] = 0;
        $curPageData["nConnect"] = 0;
        $curPageData["nRequest"] = 0;
        $curPageData["nReqs200"] = 0;
        $curPageData["nReqs302"] = 0;
        $curPageData["nReqs304"] = 0;
        $curPageData["nReqs404"] = 0;
        $curPageData["nReqsOther"] = 0;
        $curPageData["bytesOutDoc"] = 0;
        $curPageData["bytesInDoc"] = 0;
        $curPageData["nDnsLookupsDoc"] = 0;
        $curPageData["nConnectDoc"] = 0;
        $curPageData["nRequestDoc"] = 0;
        $curPageData["nReqs200Doc"] = 0;
        $curPageData["nReqs302Doc"] = 0;
        $curPageData["nReqs304Doc"] = 0;
        $curPageData["nReqs404Doc"] = 0;
        $curPageData["nReqsOtherDoc"] = 0;
        // Reset the request number on the run
        $curPageData["reqNum"] = 0;
        $curPageData["calcStarTime"] = 0;
        // Store the data for the next loops
        $pageData[$pageref] = $curPageData;
        unset($curPageData);
    }
    // Iterate the entries
    foreach ($sortedEntries as $entind => $entry) {
        // See http://www.softwareishard.com/blog/har-12-spec/#entries
        $pageref = $entry['pageref'];
        $startedDateTime = $entry['startedDateTime'];
        $entryTime = $entry['time'];
        $reqEnt = $entry['request'];
        $respEnt = $entry['response'];
        $cacheEnt = $entry['cache'];
        $timingsEnt = $entry['timings'];
        if ($reqEnt['method'] == 'HEAD') {
            continue;
        }
        // pcap2har doesn't set the server's IP address, so it may be unset:
        $reqIpAddr = arrayLookupWithDefault('serverIPAddress', $entry, null);
        // The following HAR fields are in the HAR spec, but we do not
        // use them:
        // $entry['connection']
        // $entry['comment']
        $curPageData = $pageData[$pageref];
        // Extract the variables
        $reqHttpVer = $reqEnt['httpVersion'];
        $respHttpVer = $respEnt['httpVersion'];
        $reqDate = '';
        $reqTime = '';
        if (!SplitISO6801DateIntoDateAndTime($startedDateTime, $reqDate, $reqTime)) {
            // into these parts.
            logMalformedInput("Sorted entry key 'startedDateTime' could " . "not be split into a date and time part.  " . "Value is '{$startedDateTime}'");
        }
        $reqEventName = $curPageData['title'];
        $reqAction = $reqEnt['method'];
        logMsg("Processing resource " . ShortenUrl($reqEnt['url']));
        // Skip non-http URLs (in the future we may do something with them)
        if (!preg_match("/^https?:\\/\\/([^\\/?]+)([\\/\\?].*)?/", $reqEnt['url'], $matches)) {
            logMsg("Skipping https file " . $reqEnt['url']);
            continue;
        }
        $reqUrl = $matches[2];
        $reqHost = $matches[1];
        $reqRespCode = $respEnt['status'];
        // For now, ignore status 0 responses, as we assume these are
        // cached resources.
        if ($reqRespCode == "0") {
            logMsg("Skipping resp 0 resource " . $reqEnt['url']);
            continue;
        }
        $reqRespCodeText = $respEnt['statusText'];
        $reqLoadTime = 0 + $entryTime;
        // The list is sorted by time, so use the first resource as the real start time,
        // since the start time on the page isn't always reliable (likely a bug, but this will do for now)
        if ($curPageData["calcStarTime"] == 0) {
            $curPageData["calcStarTime"] = $startedDateTime;
            $curPageData["startFull"] = $startedDateTime;
        }
        $reqStartTime = getDeltaMillisecondsFromISO6801Dates($curPageData["startFull"], $startedDateTime);
        if ($reqStartTime < 0.0) {
            logMalformedInput("Negative start offset ({$reqStartTime} mS) for request.\n" . "\$curPageData[\"startFull\"] = " . $curPageData["startFull"] . "\n" . "\$startedDateTime =          " . $startedDateTime . "\n");
        }
        $requestTimings = convertHarTimesToWebpageTestTimes($timingsEnt, $reqStartTime);
        $reqDnsTime = $requestTimings['dns_ms'];
        $reqSslTime = $requestTimings['ssl_ms'];
        $reqConnectTime = $requestTimings['connect_ms'];
        $reqBytesOut = abs($reqEnt['headersSize']) + abs($reqEnt['bodySize']);
        $reqBytesIn = abs($respEnt['headersSize']) + abs($respEnt['bodySize']);
        $reqObjectSize = abs($respEnt['bodySize']);
        $reqCookieSize = 0;
        // TODO: Calculate
        $reqCookieCount = 0;
        // TODO: Calculate
        $reqExpires = 0;
        // TODO: Calculate from cache
        $reqCacheControl = 0;
        // TODO: Extract from headers
        $reqContentType = $respEnt['content']['mimeType'];
        $reqContentEncoding = 0;
        // TODO: Extract from headers
        $reqTransType = 3;
        // TODO: Extract from headers
        $reqEndTime = $reqStartTime + $reqLoadTime;
        $reqCached = 0;
        // TODO: Extract from cache - or do we never have cached files since they aren't requested?
        $reqEventUrl = $curPageData["url"];
        $reqSecure = preg_match("/^https/", $reqEnt['url']) ? 1 : 0;
        // Variables that are likely not important
        // TODO: Check if they matter
        $reqSocketID = 3;
        $reqDocId = 3;
        $reqDescriptor = "Launch";
        $reqLabId = -1;
        $reqDialerId = 0;
        $reqConnnectionType = -1;
        // Write the line
        file_put_contents($curPageData["runFileName"], "{$reqDate}\t" . "{$reqTime}\t" . "{$reqEventName}\t" . "{$reqIpAddr}\t" . "{$reqAction}\t" . "{$reqHost}\t" . "{$reqUrl}\t" . "{$reqRespCode}\t" . $requestTimings['load'] . "\t" . $requestTimings['ttfb'] . "\t" . $requestTimings['start'] . "\t" . "{$reqBytesOut}\t" . "{$reqBytesIn}\t" . "{$reqObjectSize}\t" . "{$reqCookieSize}\t" . "{$reqCookieCount}\t" . "{$reqExpires}\t" . "{$reqCacheControl}\t" . "{$reqContentType}\t" . "{$reqContentEncoding}\t" . "{$reqTransType}\t" . "{$reqSocketID}\t" . "{$reqDocId}\t" . "{$reqEndTime}\t" . "{$reqDescriptor}\t" . "{$reqLabId}\t" . "{$reqDialerId}\t" . "{$reqConnnectionType}\t" . "{$reqCached}\t" . "{$reqEventUrl}\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "{$reqSecure}\t" . "-1\t" . "-1\t" . "-1\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "0\t" . "\t" . $requestTimings['dns_start'] . "\t" . $requestTimings['dns_end'] . "\t" . $requestTimings['connect_start'] . "\t" . $requestTimings['connect_end'] . "\t" . $requestTimings['ssl_start'] . "\t" . $requestTimings['ssl_end'] . "\t" . "\t" . "\r\n", FILE_APPEND);
        $reqNum = $curPageData["reqNum"] + 1;
        $curPageData["reqNum"] = $reqNum;
        // Write the request raw data
        file_put_contents($curPageData["reportFileName"], "Request {$reqNum}:\r\n" . "      Action: GET\r\n" . "      Url: {$reqUrl}\r\n" . "      Host: {$reqHost}\r\n" . "      Result code: {$reqRespCode}\r\n" . "      Transaction time: {$reqTime} milliseconds\r\n" . "      Time to first byte: " . $requestTimings['ttfb'] . " milliseconds\r\n" . "      Request size (out): {$reqBytesOut} Bytes\r\n" . "      Response size (in): {$reqBytesIn} Bytes\r\n" . "  Request Headers:\r\n" . "      {$reqAction} {$reqUrl} {$reqHttpVer}\r\n", FILE_APPEND);
        // Write the request/response headers
        foreach ($reqEnt['headers'] as $headercount => $header) {
            // Write the request/response headers
            file_put_contents($curPageData["reportFileName"], "      {$header['name']}: {$header['value']}\r\n", FILE_APPEND);
        }
        // Write the response raw data
        // TODO: Fill real data
        file_put_contents($curPageData["reportFileName"], "  Response Headers:\r\n" . "      {$respHttpVer} {$reqRespCode} {$reqRespCodeText}\r\n", FILE_APPEND);
        // Write the request/response headers
        foreach ($respEnt['headers'] as $headercount => $header) {
            // Write the request/response headers
            file_put_contents($curPageData["reportFileName"], "      {$header['name']}: {$header['value']}\r\n", FILE_APPEND);
        }
        // Add a newline
        file_put_contents($curPageData["reportFileName"], "\r\n", FILE_APPEND);
        // Add up the total page counters
        $curPageData["bytesOut"] += $reqBytesOut;
        $curPageData["bytesIn"] += $reqBytesIn;
        $curPageData["nDnsLookups"] += $reqDnsTime > 0 ? $reqDnsTime : 0;
        $curPageData["nConnect"] += $reqConnectTime > 0 ? $reqDnsTime : 0;
        $curPageData["nRequest"] += 1;
        if (preg_match('/^200$/', $reqRespCode)) {
            $curPageData["nReqs200"] += 1;
        } else {
            if (preg_match('/^302$/', $reqRespCode)) {
                $curPageData["nReqs302"] += 1;
            } else {
                if (preg_match('/^304$/', $reqRespCode)) {
                    $curPageData["nReqs304"] += 1;
                } else {
                    if (preg_match('/^404$/', $reqRespCode)) {
                        $curPageData["nReqs404"] += 1;
                    } else {
                        $curPageData["nReqsOther"] += 1;
                    }
                }
            }
        }
        // Add up the document complete counters, if we're before doc complete
        if ($curPageData["docComplete"] > $reqStartTime) {
            $curPageData["bytesOutDoc"] += $reqBytesOut;
            $curPageData["bytesInDoc"] += $reqBytesIn;
            $curPageData["nDnsLookupsDoc"] += $reqDnsTime > 0 ? $reqDnsTime : 0;
            $curPageData["nConnectDoc"] += $reqConnectTime > 0 ? $reqDnsTime : 0;
            $curPageData["nRequestDoc"] += 1;
            if (preg_match('/^200$/', $reqRespCode)) {
                $curPageData["nReqs200Doc"] += 1;
            } else {
                if (preg_match('/^302$/', $reqRespCode)) {
                    $curPageData["nReqs302Doc"] += 1;
                } else {
                    if (preg_match('/^304$/', $reqRespCode)) {
                        $curPageData["nReqs304Doc"] += 1;
                    } else {
                        if (preg_match('/^404$/', $reqRespCode)) {
                            $curPageData["nReqs404Doc"] += 1;
                        } else {
                            $curPageData["nReqsOtherDoc"] += 1;
                        }
                    }
                }
            }
        }
        // Find the page's time-to-first-byte which is minimum first-byte
        // time of all the requests. The request's time-to-first-byte can
        // not be used because it is relative to the start of the request,
        // not the start of the page.
        $curPageData["TTFB"] = min($curPageData["TTFB"], $requestTimings['receive_start']);
        // Update the page data variable back into the array
        $pageData[$pageref] = $curPageData;
    }
    // Create the page files
    foreach ($parsedHar['log']['pages'] as $pagecount => $page) {
        $pageref = $page['id'];
        $curPageData = $pageData[$pageref];
        // Create the page title line
        $curPageData["resourceFileName"] = $curPageData["runFilePrefix"] . "IEWPG.txt";
        file_put_contents($curPageData["resourceFileName"], "Date\tTime\tEvent Name\tURL\tLoad Time (ms)\tTime to First Byte (ms)\tunused\tBytes Out\tBytes In\tDNS Lookups\tConnections\tRequests\tOK Responses\tRedirects\tNot Modified\tNot Found\tOther Responses\tError Code\tTime to Start Render (ms)\tSegments Transmitted\tSegments Retransmitted\tPacket Loss (out)\tActivity Time(ms)\tDescriptor\tLab ID\tDialer ID\tConnection Type\tCached\tEvent URL\tPagetest Build\tMeasurement Type\tExperimental\tDoc Complete Time (ms)\tEvent GUID\tTime to DOM Element (ms)\tIncludes Object Data\tCache Score\tStatic CDN Score\tOne CDN Score\tGZIP Score\tCookie Score\tKeep-Alive Score\tDOCTYPE Score\tMinify Score\tCombine Score\tBytes Out (Doc)\tBytes In (Doc)\tDNS Lookups (Doc)\tConnections (Doc)\tRequests (Doc)\tOK Responses (Doc)\tRedirects (Doc)\tNot Modified (Doc)\tNot Found (Doc)\tOther Responses (Doc)\tCompression Score\tHost\tIP Address\tETag Score\tFlagged Requests\tFlagged Connections\tMax Simultaneous Flagged Connections\tTime to Base Page Complete (ms)\tBase Page Result\tGzip Total Bytes\tGzip Savings\tMinify Total Bytes\tMinify Savings\tImage Total Bytes\tImage Savings\tBase Page Redirects\tOptimization Checked\r\n");
        // Write the page's data
        file_put_contents($curPageData["resourceFileName"], "{$curPageData['startDate']}\t" . "{$curPageData['startTime']}\t" . "{$curPageData['title']}\t" . "{$curPageData['url']}\t" . "{$curPageData['fullyLoaded']}\t" . "{$curPageData['TTFB']}\t" . "\t" . "{$curPageData['bytesOut']}\t" . "{$curPageData['bytesIn']}\t" . "{$curPageData['nDnsLookups']}\t" . "{$curPageData['nConnect']}\t" . "{$curPageData['nRequest']}\t" . "{$curPageData['nReqs200']}\t" . "{$curPageData['nReqs302']}\t" . "{$curPageData['nReqs304']}\t" . "{$curPageData['nReqs404']}\t" . "{$curPageData['nReqsOther']}\t" . "0\t" . "{$curPageData['onRender']}\t" . "\t" . "\t" . "\t" . "{$curPageData['fullyLoaded']}\t" . "\t" . "\t" . "\t" . "\t" . "{$curPageData['cached']}\t" . "{$curPageData['url']}\t" . "\t" . "\t" . "\t" . "{$curPageData['docComplete']}\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "{$curPageData['bytesOutDoc']}\t" . "{$curPageData['bytesInDoc']}\t" . "{$curPageData['nDnsLookupsDoc']}\t" . "{$curPageData['nConnectDoc']}\t" . "{$curPageData['nRequestDoc']}\t" . "{$curPageData['nReqs200Doc']}\t" . "{$curPageData['nReqs302Doc']}\t" . "{$curPageData['nReqs304Doc']}\t" . "{$curPageData['nReqs404Doc']}\t" . "{$curPageData['nReqsOtherDoc']}\t" . "\t" . "{$curPageData['host']}\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "\t" . "0\r\n", FILE_APPEND);
    }
}
 private function _createRequestUrlLink($request, $requestNum)
 {
     if (!$request['host'] && !$request['url']) {
         return null;
     }
     $protocol = $request['is_secure'] == 1 ? "https://" : "http://";
     $url = $protocol . $request['host'] . $request['url'];
     $displayurl = ShortenUrl($url);
     if ($this->useLinks) {
         $reqUrl = '<a rel="nofollow" href="' . $url . '">' . $displayurl . '</a>';
     } else {
         $reqUrl = "<a title=\"{$url}\" href=\"#step" . $this->stepResult->getStepNumber() . "_request{$requestNum}\">{$displayurl}</a>";
     }
     return $reqUrl;
 }
Esempio n. 3
0
 }
 if (isset($tests)) {
     foreach ($tests['urls'] as &$testData) {
         RestoreTest($testData['id']);
         $path = './' . GetTestPath($testData['id']);
         if (!isset($hasCSV)) {
             $files = glob("{$path}/*{$fileType}");
             if ($files && is_array($files) && count($files)) {
                 $hasCSV = true;
             } else {
                 $hasCSV = false;
             }
         }
         $label = $testData['l'];
         if (!strlen($label)) {
             $label = htmlspecialchars(ShortenUrl($testData['u']));
         }
         if ($hasCSV) {
             if (!$sentHeader) {
                 echo "\"Test\",{$header},\"Run\",\"Cached\"";
                 if (!$is_requests) {
                     echo ',"Speed Index"';
                 }
                 echo "\r\n";
                 $sentHeader = true;
             }
             $testInfo = GetTestInfo($path);
             for ($i = 1; $i <= $test['test']['runs']; $i++) {
                 $additional = array($i, 0, SpeedIndex($path, $i, 0, $testInfo));
                 csvFile("{$path}/{$i}_{$fileType}", $label, $column_count, $additional);
                 $additional = array($i, 1, SpeedIndex($path, $i, 1, $testInfo));
 } else {
     $highlight .= 'even';
 }
 if ($request['load_start'] < $data['render']) {
     $highlight .= 'Render';
 } elseif ($request['load_start'] < $data['docTime']) {
     $highlight .= 'Doc';
 }
 echo '<td class="reqNum ' . $highlight . '">' . $requestNum . '</td>';
 if ($request['host'] || $request['url']) {
     $protocol = 'http://';
     if ($request['is_secure'] && $request['is_secure'] == 1) {
         $protocol = 'https://';
     }
     $url = $protocol . $request['host'] . $request['url'];
     $displayurl = ShortenUrl($url);
     if ($settings['nolinks']) {
         echo "<td class=\"reqUrl {$highlight}\"><a title=\"{$url}\" href=\"#request{$requestNum}\">{$displayurl}</a></td>";
     } else {
         echo '<td class="reqUrl ' . $highlight . '"><a rel="nofollow" href="' . $url . '">' . $displayurl . '</a></td>';
     }
 } else {
     echo '<td class="reqUrl ' . $highlight . '">-</td>';
 }
 echo '<td class="reqCPCODE ' . $highlight . '">' . $request['cpcode'] . '</td>';
 if (array_key_exists('responseCode', $request) && $request['responseCode']) {
     echo '<td class="respCode ' . $highlight . '">' . $request['responseCode'] . '</td>';
 } else {
     echo '<td class="respCode ' . $highlight . '">-</td>';
 }
 echo '<td class="reqLastModified ' . $highlight . '">' . $request['last-modified'] . '</td>';