PageRenderTime 29ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/details/data.php

http://showslow.googlecode.com/
PHP | 158 lines | 138 code | 20 blank | 0 comment | 20 complexity | cfd818f317438ca56eca56e80bd89bc9 MD5 | raw file
  1. <?php
  2. require_once(dirname(dirname(__FILE__)).'/global.php');
  3. if (!array_key_exists('url', $_GET) || filter_var($_GET['url'], FILTER_VALIDATE_URL) === false) {
  4. header('HTTP/1.0 400 Bad Request');
  5. ?><html>
  6. <head>
  7. <title>Bad Request: no valid url specified</title>
  8. </head>
  9. <body>
  10. <h1>Bad Request: no valid url specified</h1>
  11. <p>You must pass valid URL as 'url' parameter</p>
  12. </body></html>
  13. <?php
  14. exit;
  15. }
  16. $all = true;
  17. if (array_key_exists('profile', $_GET) && $_GET['profile'] != '' ) {
  18. $all = false;
  19. }
  20. $query = sprintf("SELECT id FROM urls WHERE urls.url = '%s'", mysql_real_escape_string($_GET['url']));
  21. $result = mysql_query($query);
  22. if (!$result) {
  23. error_log(mysql_error());
  24. }
  25. $row = mysql_fetch_assoc($result);
  26. $urlid = $row['id'];
  27. mysql_free_result($result);
  28. if ($all) {
  29. $query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) as t, y.w, y.o, y.r, y.i, y.lt,
  30. y.ynumreq, y.ycdn, y.yexpires, y.ycompress, y.ycsstop,
  31. y.yjsbottom, y.yexpressions, y.yexternal, y.ydns, y.yminify,
  32. y.yredirects, y.ydupes, y.yetags, y.yxhr, y.yxhrmethod,
  33. y.ymindom, y.yno404, y.ymincookie, y.ycookiefree, y.ynofilter,
  34. y.yimgnoscale, y.yfavicon
  35. FROM yslow2 y WHERE y.url_id = %d AND timestamp > DATE_SUB(now(), INTERVAL 3 MONTH)
  36. ORDER BY timestamp DESC",
  37. mysql_real_escape_string($urlid)
  38. );
  39. } else {
  40. $query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) as t, y.w, y.o, y.r, y.i, y.lt,
  41. y.ynumreq, y.ycdn, y.yexpires, y.ycompress, y.ycsstop,
  42. y.yjsbottom, y.yexpressions, y.yexternal, y.ydns, y.yminify,
  43. y.yredirects, y.ydupes, y.yetags, y.yxhr, y.yxhrmethod,
  44. y.ymindom, y.yno404, y.ymincookie, y.ycookiefree, y.ynofilter,
  45. y.yimgnoscale, y.yfavicon
  46. FROM yslow2 y WHERE y.url_id = %d AND y.i = '%s' AND timestamp > DATE_SUB(now(),INTERVAL 3 MONTH)
  47. ORDER BY timestamp DESC",
  48. mysql_real_escape_string($urlid), mysql_real_escape_string($_GET['profile'])
  49. );
  50. }
  51. $result = mysql_query($query);
  52. if (!$result) {
  53. error_log(mysql_error());
  54. }
  55. $data = array();
  56. header('Content-type: text/csv');
  57. if (array_key_exists('ver', $_GET)) {
  58. header('Expires: '.date('r', time() + 315569260));
  59. header('Cache-control: max-age=315569260');
  60. }
  61. $rows = array();
  62. while ($row = mysql_fetch_assoc($result)) {
  63. $rows[] = $row;
  64. }
  65. mysql_free_result($result);
  66. if (array_key_exists('smooth', $_REQUEST)) {
  67. require_once(dirname(__FILE__).'/smooth.php');
  68. smooth($rows, array('w', 'o', 'r', 'lt'));
  69. }
  70. if (!array_key_exists('subset', $_REQUEST) || !$_REQUEST['subset'] == 'graph')
  71. {
  72. header('Content-disposition: attachment;filename=yslow.csv');
  73. echo '# Measurement time, ';
  74. echo 'Page size (in bytes), ';
  75. echo 'YSlow grade, ';
  76. echo 'Total number requests, ';
  77. echo 'Page Load Time, ';
  78. echo "YSlow profile used, ";
  79. echo 'Make fewer HTTP requests, ';
  80. echo 'Use a Content Delivery Network (CDN), ';
  81. echo 'Add Expires headers, ';
  82. echo 'Compress components with gzip, ';
  83. echo 'Put CSS at top, ';
  84. echo 'Put JavaScript at bottom, ';
  85. echo 'Avoid CSS expressions, ';
  86. echo 'Make JavaScript and CSS external, ';
  87. echo 'Reduce DNS lookups, ';
  88. echo 'Minify JavaScript and CSS, ';
  89. echo 'Avoid URL redirects, ';
  90. echo 'Remove duplicate JavaScript and CSS, ';
  91. echo 'Configure entity tags (ETags), ';
  92. echo 'Make AJAX cacheable, ';
  93. echo 'Use GET for AJAX requests, ';
  94. echo 'Reduce the number of DOM elements, ';
  95. echo 'Avoid HTTP 404 (Not Found) error, ';
  96. echo 'Reduce cookie size, ';
  97. echo 'Use cookie-free domains, ';
  98. echo 'Avoid AlphaImageLoader filter, ';
  99. echo 'Do not scale images in HTML, ';
  100. echo 'Make favicon small and cacheable';
  101. echo "\n";
  102. }
  103. foreach ($rows as $row) {
  104. echo date('c', $row['t']).','.
  105. ($row['i'] == 'yslow1' ? $row['w'] * 1024 : $row['w']).','.
  106. $row['o'].','.
  107. $row['r'].','.
  108. $row['lt'].','.
  109. $row['i'];
  110. if (array_key_exists('subset', $_REQUEST) && $_REQUEST['subset'] == 'graph')
  111. {
  112. echo "\n";
  113. } else {
  114. echo ','.$row['ynumreq'].','.
  115. $row['ycdn'].','.
  116. $row['yexpires'].','.
  117. $row['ycompress'].','.
  118. $row['ycsstop'].','.
  119. $row['yjsbottom'].','.
  120. $row['yexpressions'].','.
  121. $row['yexternal'].','.
  122. $row['ydns'].','.
  123. $row['yminify'].','.
  124. $row['yredirects'].','.
  125. $row['ydupes'].','.
  126. $row['yetags'].','.
  127. $row['yxhr'].','.
  128. $row['yxhrmethod'].','.
  129. $row['ymindom'].','.
  130. $row['yno404'].','.
  131. $row['ymincookie'].','.
  132. $row['ycookiefree'].','.
  133. $row['ynofilter'].','.
  134. $row['yimgnoscale'].','.
  135. $row['yfavicon'].
  136. "\n";
  137. }
  138. }