PageRenderTime 2191ms CodeModel.GetById 2181ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/details/data_pagespeed.php

http://showslow.googlecode.com/
PHP | 119 lines | 100 code | 19 blank | 0 comment | 14 complexity | be36b04042cda634d09c4cc8438ad7f9 MD5 | raw file
  1<?php 
  2require_once(dirname(dirname(__FILE__)).'/global.php');
  3
  4if (!array_key_exists('url', $_GET) || filter_var($_GET['url'], FILTER_VALIDATE_URL) === false) {
  5	header('HTTP/1.0 400 Bad Request');
  6
  7	?><html>
  8<head>
  9<title>Bad Request: no valid url specified</title>
 10</head>
 11<body>
 12<h1>Bad Request: no valid url specified</h1>
 13<p>You must pass valid URL as 'url' parameter</p>
 14</body></html>
 15<?php 
 16	exit;
 17}
 18
 19$query = sprintf("SELECT id FROM urls WHERE urls.url = '%s'", mysql_real_escape_string($_GET['url']));
 20$result = mysql_query($query);
 21
 22if (!$result) {
 23	error_log(mysql_error());
 24}
 25
 26$row = mysql_fetch_assoc($result);
 27$urlid = $row['id'];
 28mysql_free_result($result);
 29
 30$query = sprintf("SELECT UNIX_TIMESTAMP(p.timestamp) as time,
 31		p.w, p.o, p.l, p.r, p.t, p.v,
 32		pBadReqs, pBrowserCache, pCacheValid, pCharsetEarly, pCombineCSS,
 33		pCombineJS, pCssImport, pCssInHead, pCssJsOrder, pCssSelect,
 34		pDeferJS, pDocWrite, pDupeRsrc, pGzip, pImgDims,
 35		pMinDns, pMinifyCSS, pMinifyHTML, pMinifyJS, pMinRedirect,
 36		pMinReqSize, pNoCookie, pOptImgs, pParallelDl, pPreferAsync,
 37		pRemoveQuery, pScaleImgs, pSprite, pUnusedCSS, pVaryAE
 38	FROM pagespeed p WHERE p.url_id = %d AND p.timestamp > DATE_SUB(now(),INTERVAL 3 MONTH)
 39ORDER BY p.timestamp DESC",
 40mysql_real_escape_string($urlid)
 41);
 42
 43$result = mysql_query($query);
 44
 45if (!$result) {
 46        error_log(mysql_error());
 47}
 48
 49$data = array();
 50
 51header('Content-type: text/plain');
 52if (array_key_exists('ver', $_GET)) {
 53	header('Expires: '.date('r', time() + 315569260));
 54	header('Cache-control: max-age=315569260');
 55}
 56
 57$rows = array();
 58while ($row = mysql_fetch_assoc($result)) {
 59	$rows[] = $row;
 60}
 61
 62mysql_free_result($result);
 63
 64if (array_key_exists('smooth', $_REQUEST)) {
 65	require_once(dirname(__FILE__).'/smooth.php');
 66	smooth($rows, array('w', 'o', 'r', 'l'));
 67}
 68
 69if (!array_key_exists('subset', $_REQUEST) || !$_REQUEST['subset'] == 'graph')
 70{
 71	header('Content-disposition: attachment;filename=pagespeed.csv');
 72}
 73
 74echo '# Measurements gathered for '.$_GET['url']."\n";
 75
 76foreach ($rows as $row) {
 77
 78        echo date('c', $row['time']).','.
 79		$row['w'].','.$row['o'].','.$row['l'].','.$row['r'];
 80
 81		if (array_key_exists('subset', $_REQUEST) && $_REQUEST['subset'] == 'graph')
 82		{
 83			echo "\n";
 84		} else {
 85			echo ','.$row['t'].','.$row['v'].','.
 86			$row['pBadReqs'].','.
 87			$row['pBrowserCache'].','.
 88			$row['pCacheValid'].','.
 89			$row['pCharsetEarly'].','.
 90			$row['pCombineCSS'].','.
 91			$row['pCombineJS'].','.
 92			$row['pCssImport'].','.
 93			$row['pCssInHead'].','.
 94			$row['pCssJsOrder'].','.
 95			$row['pCssSelect'].','.
 96			$row['pDeferJS'].','.
 97			$row['pDocWrite'].','.
 98			$row['pDupeRsrc'].','.
 99			$row['pGzip'].','.
100			$row['pImgDims'].','.
101			$row['pMinDns'].','.
102			$row['pMinifyCSS'].','.
103			$row['pMinifyHTML'].','.
104			$row['pMinifyJS'].','.
105			$row['pMinRedirect'].','.
106			$row['pMinReqSize'].','.
107			$row['pNoCookie'].','.
108			$row['pOptImgs'].','.
109			$row['pParallelDl'].','.
110			$row['pPreferAsync'].','.
111			$row['pRemoveQuery'].','.
112			$row['pScaleImgs'].','.
113			$row['pSprite'].','.
114			$row['pUnusedCSS'].','.
115			$row['pVaryAE'].','.
116			"\n";
117		}
118}
119