PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/dist/webpagetest/www/running.inc

http://webpagetest.googlecode.com/
PHP | 165 lines | 158 code | 3 blank | 4 comment | 30 complexity | 2965523e3840da5be5399115faefcfce MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-3.0, LGPL-3.0, MIT, BSD-3-Clause, ISC, LGPL-2.1
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>WebPagetest - Running web page performance and optimization test...</title>
  5. <noscript>
  6. <meta http-equiv="refresh" content="30" />
  7. </noscript>
  8. <?php
  9. $autoRefresh = true;
  10. $noanalytics = true;
  11. $page_keywords = array('Webpagetest','Website Speed Test','Page Speed');
  12. $page_description = "Running website performance test.";
  13. include ('head.inc');
  14. ?>
  15. </head>
  16. <body>
  17. <div class="page">
  18. <?php
  19. require_once('testStatus.inc');
  20. $tab = 'Test Result';
  21. include 'header.inc';
  22. if( !isset($test) )
  23. {
  24. echo "<h3>Test Not Found</h3>\n";
  25. echo "<p>Sorry, the test you requested could not be found.</p>";
  26. }
  27. else
  28. {
  29. ?>
  30. <div id="runningHeader">
  31. <p>
  32. <?php
  33. if ($settings['nolinks']) {
  34. echo "Url: $url<br>\n";
  35. } else {
  36. echo "Url: <a rel=\"nofollow\" href=\"$url\">$url</a><br>\n";
  37. }
  38. echo "From: {$test['test']['location']}<br>\n";
  39. echo GetTestInfoHtml(false);
  40. ?>
  41. </p>
  42. <h3>Testing...</h3>
  43. <?php
  44. $status = GetTestStatus($id, true);
  45. if ( !$status['startTime'] )
  46. {
  47. ?>
  48. <form action="/cancelTest.php" method="get">
  49. <input type="hidden" name="test" value="<?php echo $id;?>">
  50. <input type="submit" value="Cancel Test"/>
  51. </form>
  52. <?php
  53. }
  54. ?>
  55. </div>
  56. <?php
  57. $statusText = $status['statusText'];
  58. ?>
  59. <div id="statusImg">
  60. <?php
  61. $img = "waiting";
  62. if( $status['startTime'] )
  63. $img = "testing";
  64. echo "<img id='statusImage' src=\"{$GLOBALS['cdnPath']}/images/status_$img.png\">";
  65. echo "<div id=\"statusText\">$statusText</div>\n";
  66. ?>
  67. </div>
  68. <?php
  69. $tip = GetTip();
  70. if( strlen($tip) )
  71. {
  72. echo '<table class="tip"><tr><th>Did you know...<span class="tip_note">(all links open in a new window/tab)</span></th></tr><tr><td>';
  73. echo $tip;
  74. echo "</td></table>\n";
  75. }
  76. ?>
  77. <p>Your web page performance test has been submitted and is now being processed. This page will automatically update with the test status as
  78. the test continues to run and when the test is complete the final results will be available here.</p>
  79. <p>You can either leave this page open in your browser until the test
  80. is complete or come back later and check on the status of the test (the browser does not need to remain open for testing to continue).</p>
  81. <br>
  82. <?php } include('footer.inc'); ?>
  83. </div>
  84. <script type="text/javascript">
  85. var testId = "<?php echo $id; ?>";
  86. var pollingInterval = 5000;
  87. var pollingIntervalTesting = 1000;
  88. var waitingImage = '<?php echo "{$GLOBALS['cdnPath']}/images/status_waiting.png"; ?>';
  89. var testingImage = '<?php echo "{$GLOBALS['cdnPath']}/images/status_testing.png"; ?>';
  90. var lastStatusCode = 0;
  91. var lastStatusText = '';
  92. function UpdateStatus(){
  93. try {
  94. var xhr = new XMLHttpRequest();
  95. xhr.open('GET', '/testStatus.php?f=json&pos=1&test=' + testId, true);
  96. xhr.onreadystatechange = function() {
  97. if (xhr.readyState != 4)
  98. return;
  99. var reload = false;
  100. var interval = pollingInterval;
  101. if (xhr.status == 200) {
  102. var response = JSON.parse(xhr.responseText);
  103. if (response['statusCode'] != undefined &&
  104. response['statusCode'] != lastStatusCode) {
  105. lastStatusCode = response['statusCode'];
  106. if (lastStatusCode == 101)
  107. $("#statusImage").attr("src",waitingImage);
  108. else if (lastStatusCode == 100)
  109. $("#statusImage").attr("src",testingImage);
  110. else
  111. reload = true;
  112. }
  113. if (lastStatusCode == 100) {
  114. interval = pollingIntervalTesting;
  115. if (response['data'] != undefined &&
  116. !response.data['remote'] &&
  117. response.data['testsCompleted'] != undefined &&
  118. response.data['testsCompleted'] >= 1)
  119. reload = true;
  120. }
  121. if (response['statusText'] != undefined &&
  122. response['statusText'] != lastStatusText) {
  123. lastStatusText = response['statusText'];
  124. $('#statusText').text(lastStatusText);
  125. }
  126. }
  127. if (reload)
  128. window.location.reload(true);
  129. else
  130. setTimeout('UpdateStatus()', interval);
  131. };
  132. xhr.onerror = function() {
  133. setTimeout('UpdateStatus()', pollingInterval);
  134. };
  135. xhr.send();
  136. } catch (err) {
  137. setTimeout('UpdateStatus()', pollingInterval);
  138. }
  139. }
  140. setTimeout('UpdateStatus()', pollingInterval);
  141. </script>
  142. </body>
  143. </html>
  144. <?php
  145. /**
  146. * Load a tip
  147. *
  148. */
  149. function GetTip()
  150. {
  151. $tip = '';
  152. $tips = glob('./tips_data/*.html',GLOB_NOSORT);
  153. $count = count($tips);
  154. if( $count > 0 )
  155. {
  156. $pick = rand(0, $count - 1);
  157. $file = $tips[$pick];
  158. $tip = file_get_contents($file);
  159. }
  160. return $tip;
  161. }
  162. ?>