AJAX
[ class tree: AJAX ] [ index: AJAX ] [ all elements ]

Source for file test_priority.php

Documentation is available at test_priority.php

  1. <?php
  2. /**
  3.  * Priority queue test.
  4.  *
  5.  * Makes 10 calls at one priority, then 10 calls at a higher priority.
  6.  *
  7.  * @category   HTML
  8.  * @package    AJAX
  9.  * @author     Arpad Ray <arpad@php.net>
  10.  * @copyright  2005 Arpad Ray
  11.  * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
  12.  * @version    Release: @package_version@
  13.  * @link       http://pear.php.net/package/HTML_AJAX
  14.  */
  15.  
  16. include 'HTML/AJAX.php';
  17. include '../support/test.class.php';
  18.  
  19. $ajax = new HTML_AJAX();
  20. $ajax->serializer = "Null";
  21. $ajax->unserializer = "Null";
  22. $ajax->registerClass(new test());
  23.  
  24. if ($ajax->handleRequest()) {
  25.     die();
  26. }
  27. ?><html>
  28. <head>
  29. <script type='text/javascript' src="../server.php?client=all&amp;stub=all"></script>
  30. <script type="text/javascript">
  31.  
  32. HTML_AJAX.queues['priority'] = new HTML_AJAX_Queue_Priority_Simple(40);
  33.  
  34. var t = new test({echo_string: function(result){ endCall(result); }});
  35.  
  36. var time1;
  37. var count = 0;
  38.  
  39. function priorityTest() {
  40.     document.getElementById('target').innerHTML += "<br><br>";
  41.     count = 0;
  42.     for (var i = 0; i < 10; i++) {
  43.         runLow(i);
  44.     }
  45.     for (var i = 0; i < 10; i++) {
  46.         runHigh(i);
  47.     }
  48.     total = 0;
  49. }
  50. function runLow(i) {
  51.     startCall();
  52.     t.dispatcher.queue = 'priority';
  53.     t.dispatcher.priority = 10;
  54.     return t.echo_string('Not urgent, number ' + i + ' ');
  55. }
  56. function runHigh(i) {
  57.     startCall();
  58.     t.dispatcher.queue = 'priority';
  59.     t.dispatcher.priority = 0;
  60.     return t.echo_string('Urgent, number ' + i + ' ');
  61. }
  62. function startCall() {
  63.     time1 = new Date();
  64. }
  65. function endCall(name) {
  66.     var time = 0;
  67.     var time2 = new Date();
  68.     time = time2.getTime() - time1.getTime();
  69.     
  70.     document.getElementById('target').innerHTML += name + "time: " + time + "<br>";
  71.     if (++count == 20) {
  72.         document.getElementById('target').innerHTML += "Done<br>";
  73.     }
  74. }
  75.  
  76. </script>
  77. </head>
  78. <body>
  79. <a href="javascript:priorityTest()">Start Priority Test</a>
  80. <div id="target">
  81. </div>
  82. </body>
  83. </html>

Documentation generated on Sat, 05 May 2007 18:00:24 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.