cvs: pear /HTML_AJAX/examples/tests behaviorSpeed.php duplicateJSLib.php js_utils_getElements.php js_utils_vardump.php serialize.php.examples.php
serialize.url.examples.php setInnerHTML.js setInnerHTML.php test_behavior.html test_priority.php test_speed.php

From: Date: Fri, 13 Oct 2006 15:26:36 +0000
Subject: cvs: pear /HTML_AJAX/examples/tests behaviorSpeed.php duplicateJSLib.php js_utils_getElements.php js_utils_vardump.php serialize.php.examples.php
serialize.url.examples.php setInnerHTML.js setInnerHTML.php test_behavior.html test_priority.php test_speed.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42524@lists.php.net to get a copy of this message
davidc Fri Oct 13 15:26:36 2006 UTC Added files: /pear/HTML_AJAX/examples/tests behaviorSpeed.php duplicateJSLib.php js_utils_getElements.php js_utils_vardump.php serialize.php.examples.php serialize.url.examples.php setInnerHTML.js setInnerHTML.php test_behavior.html test_priority.php test_speed.php Log: - Various tests

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/behaviorSpeed.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/behaviorSpeed.php +++ pear/HTML_AJAX/examples/tests/behaviorSpeed.php <html> <head> <title>Behavior Speed Test</title> <script type="text/javascript" src="../server.php?client=util,main,alias,behavior"></script> <script type="text/javascript"> Behavior.debug = 'debug'; Behavior.register('.one',function(element) { element.style.color = 'red'; } ); Behavior.register('.two',function(element) { element.style.color = 'blue'; } ); Behavior.register('.three',function(element) { element.style.color = 'green'; } ); Behavior.register('.four',function(element) { element.style.color = 'orange'; } ); Behavior.register('.five',function(element) { element.style.color = 'purple'; } ); </script> </head> <body> <p>This page is used to test the speed of HTML_AJAX's JavaScript Behavior support.</p> <pre id="debug"> </pre> <?php $classes = array('one','two','three','four','five'); for($i = 0; $i < 100; $i++) { $class = $classes[array_rand($classes)]; echo "<div class='$class' id='el$i'>$class"; for($b = 0; $b < 50; $b++) { $c = $classes[array_rand($classes)]; echo "<span class='$c' id='el$i$b'>$c</span>"; } echo "</div>\n"; } ?> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/duplicateJSLib.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/duplicateJSLib.php +++ pear/HTML_AJAX/examples/tests/duplicateJSLib.php <?php /** * Duplicate JS files are automatically removed by HTML_AJAX_Server * * This is a test for that functionality */ ?> <html> <head> <title>Duplicate JS library Test</title> <script src="../server.php?client=Queue,orderedQueue,priorityqueue"></script> </head> <body> <p>Nothing to see here, view: <a href="../server.php?client=Queue,orderedQueue,priorityqueue">../server.php?client=Queue,orderedQueue,priorityQueue</a> to test</p> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/js_utils_getElements.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/js_utils_getElements.php +++ pear/HTML_AJAX/examples/tests/js_utils_getElements.php <?php /** * HTML_AJAX_Util.getElements*() examples * * @category HTML * @package AJAX * @author Joshua Eichorn josh@bluga.net * @copyright 2006 Joshua Eichorn * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_AJAX */ ?> <html> <head> <title>HTML_AJAX_Util.getElements* examples</title> <script type="text/javascript" src="../server.php?client=util"></script> </head> <body> <div id="t"> <div id="test_one" class="test">Blah</div> <div id="test_two" class="yellow">blah 2</div> <div id="three" class="test">Blah 3</div> </div> <h3>Test HTML</h3> <pre id="target0"></pre> <h3>getElementsByClassName</h3> <div id="target1"></div> <h3>getElementsById</h3> <div id="target2"></div> <script type="text/javascript"> document.getElementById('target0').innerHTML = HTML_AJAX_Util.htmlEscape(document.getElementById('t').innerHTML); var els = HTML_AJAX_Util.getElementsByClassName('test'); var t = document.getElementById('target1'); for(var i = 0; i < els.length; i++) { t.innerHTML += "Found: "+els[i].innerHTML+"<br>"; } var els = HTML_AJAX_Util.getElementsById('test'); var t = document.getElementById('target2'); for(var i = 0; i < els.length; i++) { t.innerHTML += "Found: "+els[i].innerHTML+"<br>"; } </script> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/js_utils_vardump.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/js_utils_vardump.php +++ pear/HTML_AJAX/examples/tests/js_utils_vardump.php <?php /** * HTML_AJAX_Util.varDump() examples * * @category HTML * @package AJAX * @author Arpad Ray <arpad@php.net> * @copyright 2005 Arpad Ray * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_AJAX */ ?> <html> <head> <script type="text/javascript" src="../server.php?client=util"></script> <script type="text/javascript"> function foo() { this.bar = "baz"; this.bat = 5; } var obj = new foo(); var a = [ null, true, 13, 1.337, 'foo', [1, 2, 3], [1, [1, 2, 3], 3], obj ]; function dotest() { var foo = document.getElementById("foo"); for (ak in a) { foo.innerHTML += "<pre>" + HTML_AJAX_Util.varDump(a[ak], 1) + "</pre><br>"; } } </script></head><body onload="dotest()"> <hr> PHP: <hr> <div> <?php class foo { var $bar = 'baz'; var $bat = 5; } $obj = new foo; $a = array( null, true, 13, 1.337, 'foo', array(1, 2, 3), array(1, array(1, 2, 3), 3), $obj ); foreach ($a as $v) { echo "<pre>"; var_dump($v); echo "</pre>"; } ?> </div> <hr> Javascript: <hr> <div id="foo"> </div> <hr> Source: <hr> <div> <?php show_source(__FILE__); ?> </div> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/serialize.php.examples.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/serialize.php.examples.php +++ pear/HTML_AJAX/examples/tests/serialize.php.examples.php <script type="text/javascript" src="../server.php?client=phpSerializer,util"></script> <?php $examples = array( '$foo = null;', '$foo = true;', '$foo = "foobar";', '$foo = 337;', '$foo = 99.99;', '$foo = array("a" => 1, "b" => 2, 3);', '$foo = array(1,2,array(1,2,3));', 'class Foo { var $foo; var $bar; }' . '$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");' ); echo '<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1>'; $c = count($examples); for ($i = 0; $i < $c; $i++) { echo "<strong>PHP Code:</strong>\n<pre>$examples[$i]</pre>\n<strong>PHP value:</strong><pre>\n"; eval($examples[$i]); var_dump($foo); $sfoo = serialize($foo); echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>", $sfoo, "</pre>\n", "<strong>Unserialized in JS:</strong>\n<pre>\n", '<script type="text/javascript">', 'var jsr = new HTML_AJAX_Serialize_PHP();', 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = jsr.unserialize(sfoo); if (jsr.error) {', 'document.write("Error: " + jsr.getError() + "\n"); } document.write(HTML_AJAX_Util.varDump(usfoo) + ', '"</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + jsr.serialize(usfoo));', "</script>\n</pre>\n<hr />\n\n"; } $bad_examples = array( 'x', 'x:1', 'N', 'Nx', 'b:f;', 'b:1', 'i:foo;', 'i:1', 'd:foo;', 'd:1.1.1;', 'd:1.1', 's:6:"foo";', 's:6:"foofoo"', 's:1:"foo";', 's:0:""', 'a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}', 'a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;', 'a:3:{i:1;s:1:"b";i:2;i:0;i:3;}', 'a:3:{}', 'O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', 'O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', 'O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}', 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}' ); echo '<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1>'; foreach ($bad_examples as $sfoo) { echo "</pre>\n<strong>Invalidly serialized:</strong>\n<pre>", $sfoo, "</pre>\n", "<strong>Unserialized in JS:</strong>\n<pre>\n", '<script type="text/javascript">', 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = jsr.unserialize(sfoo); if (jsr.error) {', 'document.write("Error: " + jsr.getError() + "\n"); } document.write(HTML_AJAX_Util.varDump(usfoo));', "</script>\n</pre>\n<hr />\n\n"; } $good_objects = array( 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', 'O:3:"Foo":2:{s:3:"foo";s:87:"O:3:"Bar":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', 'O:3:"Foo":2:{s:3:"foo";s:90:"hi"O:3:"Bar":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}' ); $bad_objects = array( 'O:6:"stdClass":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', 'O:3:"Foo":2:{s:3:"foo";O:8:"stdClass":1:{s:3:"bar";s:2:"hi";}s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', 'O:3:"Foo":2:{s:6:"hi"foo";O:8:"stdClass":1:{s:3:"bar";s:2:"hi";}s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}' ); include('HTML/AJAX/Serializer/PHP.php'); $sr = new HTML_AJAX_Serializer_PHP; $allowedClasses = array('Foo'); echo '<h1><a name="opos">Object Positives</a> | <a href="#oneg">Object Negatives</a></h1>'; foreach ($good_objects as $sfoo) { echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>", $sfoo, "</pre>\n", "<strong>Class Names</strong><pre>\n", implode(', ', $sr->_getSerializedClassNames($sfoo)), "</pre><strong>Unserialized in PHP:</strong>\n<pre>\n"; var_dump($sr->unserialize($sfoo, $allowedClasses)); echo "</pre>\n<hr />\n\n"; } echo '<h1><a href="#opos">Object Positives</a> | <a name="oneg">Object Negatives</a></h1>'; foreach ($bad_objects as $sfoo) { echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>", $sfoo, "</pre>\n", "<strong>Class Names</strong><pre>\n", implode(', ', $sr->_getSerializedClassNames($sfoo)), "</pre><strong>Unserialized in PHP:</strong>\n<pre>\n"; var_dump($sr->unserialize($sfoo, $allowedClasses)); echo "</pre>\n<hr />\n\n"; } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/serialize.url.examples.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/serialize.url.examples.php +++ pear/HTML_AJAX/examples/tests/serialize.url.examples.php <?php /** * Test cases for the UrlSerializer */ ?> <script type="text/javascript" src="../server.php?client=UrlSerializer,util"></script> <script type="text/javascript"> </script> <?php $examples = array( '$foo = null;', '$foo = true;', '$foo = "foobar";', '$foo = 337;', '$foo = 99.99;', '$foo = array("a" => 1, "b" => 2, 3);', '$foo = array(1,2,array(1,2,3));', 'class Foo { var $foo; var $bar; }' . '$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");' ); require_once 'HTML/AJAX/Serializer/Urlencoded.php'; $sr = new HTML_AJAX_Serializer_Urlencoded; echo '<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1>'; $c = count($examples); for ($i = 0; $i < $c; $i++) { echo "<strong>PHP Code:</strong>\n<pre>$examples[$i]</pre>\n<strong>PHP value:</strong><pre>\n"; eval($examples[$i]); var_dump($foo); $sfoo = $sr->serialize($foo); echo "</pre>\n<strong>Unserialized in PHP:</strong>\n<pre>"; var_dump($sr->unserialize($sfoo)); echo "</pre>\n<strong>Unserialized in JS:</strong>\n<pre>\n", '<script type="text/javascript">', 'var jsr = new HTML_AJAX_Serialize_Urlencoded();', 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = jsr.unserialize(sfoo); if (jsr.error) {', 'document.write("Error: " + jsr.getError() + "\n"); } document.write(HTML_AJAX_Util.varDump(usfoo) + ', '"</pre>\n<strong>Serialized in PHP:</strong>\n<pre>', $sfoo, '</pre>\n', '\n<strong>Serialized in JS:</strong>\n<pre>" + jsr.serialize(usfoo));', "\n</script>\n</pre>\n<hr />\n\n"; } $bad_examples = array( 'x', 'x-1', 'x=1x=2', 'x=1&', 'x[=]1', '[]x=1', '_HTML_AJAX]]=1', '_HTML_AJAX[[=1', '_HTML_AJAX][=1', '_HTML_AJAX[=]1', '_HTML_AJAX[=1]', '_HTML_AJAX[0]=1&_HTML_AJAX]]=1', '_HTML_AJAX[0[1]]=1', '_HTML_AJAX[0[1]=1' ); echo '<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1>'; foreach ($bad_examples as $sfoo) { echo "</pre>\n<strong>Invalidly serialized:</strong>\n<pre>", $sfoo, "</pre>\n", "<strong>Unserialized in JS:</strong>\n<pre>\n", '<script type="text/javascript">', 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = jsr.unserialize(sfoo); if (jsr.error) {', 'document.write("Error: " + jsr.getError() + "\n"); } document.write(HTML_AJAX_Util.varDump(usfoo));', "</script>\n</pre>\n<hr />\n\n"; } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/setInnerHTML.js?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/setInnerHTML.js +++ pear/HTML_AJAX/examples/tests/setInnerHTML.js alert('Loaded setInnerHTML.js'); http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/setInnerHTML.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/setInnerHTML.php +++ pear/HTML_AJAX/examples/tests/setInnerHTML.php <?php /** * HTML_AJAX_Util.setInnerHTML tests * * @category HTML * @package AJAX * @author Joshua Eichorn <josh@bluga.net> * @copyright 2006 Joshua Eichorn * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_AJAX */ ?> <html> <head> <style type="text/css"> div { padding: 1em; margin: 1em; border: solid 1px black; } pre { padding: 1em; border: dotted 1px black; } </style> <script type="text/javascript" src="../server.php?client=util"></script> <script type="text/javascript"> function test(compareto,input,mode) { if (compareto == true) { compareto = input; } document.getElementById('input').innerHTML = HTML_AJAX_Util.htmlEscape(input); HTML_AJAX_Util.setInnerHTML('target',input,mode); document.getElementById('source').innerHTML = HTML_AJAX_Util.htmlEscape(document.getElementById('target').innerHTML); document.getElementById('status').innerHTML = 'Test Successful'; document.getElementById('status').style.color = 'green'; if (compareto == false) { document.getElementById('status').innerHTML = 'Nothing to compare against'; document.getElementById('status').style.color = 'yellow'; return; } if (compareto != document.getElementById('target').innerHTML) { document.getElementById('status').innerHTML = 'Test Failed'; document.getElementById('status').style.color = 'red'; } } function test1() { test(true,'<script type="text/javascript">alert("hello world");</'+'script>'); } function test2() { test(true,'<div id="blah">Blah Blah</div><script type="text/javascript">document.getElementById("target").style.color = "blue";</'+'script><div>blah blah</div>'); } function test3() { test(true,'<script type="text/javascript">function blah() { document.getElementById("target").style.color = "blue"; }</'+'script><div>Blah Blah</div><script type="text/javascript">blah();</'+'script><div>blah blah</div>'); } function test4() { test(true,'<script type="text/javascript">function blah() { document.getElementById("target").style.color = "blue"; }</'+'script>'+"\n"+ '<form><fieldset><legend>Fieldset</legend>'+"\n"+ '<div>Blah Blah</div>'+"\n"+ '<script type="text/javascript">blah();</'+'script>'+"\n"+ '<div>blah blah</div></fieldset></form>'); } function test5() { test(false,'<div>start</div>'); test('<div>Add</div><div>start</div>','<div>Add</div>','prepend'); } function test6() { test(false,'<div>start</div>'); test('<div>start</div><div>Add</div>','<div>Add</div>','append'); } function test7() { test(false,'<img src="http://phpdoc.org/images/logo-trans.png" onload="this.style.border = \'solid 10px orange\'">'); } function test8() { test(false,'<script type="text/javascript">document.write("Hello World")</'+'script>'); } function test9() { test(false,'<script type="text/javascript" src="setInnerHTML.js"></'+'script>'); } function test10() { test(false,'<script type="text/javascript">function blah() { document.getElementById("target").style.color = "blue"; }</'+'script>Test'); blah(); } function test11() { HTML_AJAX_Util.setInnerHTML('target','<p>blah</p>'); HTML_AJAX_Util.setInnerHTML('target','<p>blah</a>'); } function test12() { test(false,'<div id="test12">Blah</div><script type="text/javascript">document.getElementById("test12").style.color = "orange";</s'+'cript>'); } function test13() { test(false, '<script type="text/javascript">\n<!--\n alert("hello world from comments!");\n//-->\n</' + 'script>'); } function test14() { test(false, '<script type="text/javascript">\n<![CDATA[\n alert("hello world from cdata comments!");\n]]>\n</' + 'script>'); } </script> </head> <body> <ol> <li><a href="javascript:test1()">Basic Test just a script block</a></li> <li><a href="javascript:test2()">Script block with content before and after</a></li> <li><a href="javascript:test3()">Script content Script content</a></li> <li><a href="javascript:test4()">Script form content Script content /form</a></li> <li><a href="javascript:test5()">Prepend</a></li> <li><a href="javascript:test6()">Append</a></li> <li><a href="javascript:test7()">onload</a></li> <li><a href="javascript:test8()">document.write</a></li> <li><a href="javascript:test9()">load an external js file</a></li> <li><a href="javascript:test10()">Create a function and call it in the parent scope</a></li> <li><a href="javascript:test11()">Replace/Replace make sure default mode is detected properly</a></li> <li><a href="javascript:test12()">Use an element adding in this set latter in the process</a></li> <li><a href="javascript:test13()">Script inside comment</a></li> <li><a href="javascript:test14()">Script inside cdata comment</a></li> </ol> <div id="status"></div> <h3>Input String</h3> <pre id="input"> </pre> <h3>HTML Source Output</h3> <pre id="source"> </pre> <h3>Normal Output</h3> <div id="target"> </div> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/test_behavior.html?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/test_behavior.html +++ pear/HTML_AJAX/examples/tests/test_behavior.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> How to use behavior.js </title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="../server.php?client=behavior" type="text/javascript"></script> <script type="text/javascript"> Behavior.register( ".alert", function(element) { element.onclick = function(){ alert('I alert on click'); } } ); Behavior.register( ".annoy", function(element) { element.onmouseout = function(){ alert('I alert on mouseout, very annoying'); } } ); Behavior.register( ".red", function(element) { element.onmouseover = function(){ element.style.backgroundColor = 'red'; } } ); </script> </head> <body> <p> This file requires two javascript files to work properly. They are behavior.js and css-Query-p.js and can be found in the js/behaviors folder. The script allows you to apply behaviors to a css class, so you don't pollute your html with a ton of inline javascript. The example below uses the following script tag to apply the behaviors. you can also link external javascript files to apply behaviors as well. </p> <pre> Behavior.register( ".alert", function(element) { element.onclick = function(){ alert('I alert on click'); } } ); Behavior.register( ".annoy", function(element) { element.onmouseout = function(){ alert('I alert on mouseout, very annoying'); } } ); Behavior.register( ".red", function(element) { element.onmouseover = function(){ element.style.backgroundColor = 'red'; } } ); </pre> <div style="border: 1px solid black; width: 50%; margin: 5em"> <div class="alert"> I am a div that alerts when you click on me - notice I just have class="alert" to make it work :) </div> <div class="annoy"> I am a div that alerts when you mouseout me - class="annoy" makes it work </div> <div class=" alert red"> I am a div that alerts when you click on me and the background turns red on mouseover - class="alert red" </div> </div> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/test_priority.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/test_priority.php +++ pear/HTML_AJAX/examples/tests/test_priority.php <?php /** * Priority queue test. * * Makes 10 calls at one priority, then 10 calls at a higher priority. * * @category HTML * @package AJAX * @author Arpad Ray <arpad@php.net> * @copyright 2005 Arpad Ray * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_AJAX */ include 'HTML/AJAX.php'; include '../support/test.class.php'; $ajax = new HTML_AJAX(); $ajax->serializer = "Null"; $ajax->unserializer = "Null"; $ajax->registerClass(new test()); if ($ajax->handleRequest()) { die(); } ?><html> <head> <script type='text/javascript' src="../server.php?client=all&amp;stub=all"></script> <script type="text/javascript"> HTML_AJAX.queues['priority'] = new HTML_AJAX_Queue_Priority_Simple(40); var t = new test({echo_string: function(result){ endCall(result); }}); var time1; var count = 0; function priorityTest() { document.getElementById('target').innerHTML += "<br><br>"; count = 0; for (var i = 0; i < 10; i++) { runLow(i); } for (var i = 0; i < 10; i++) { runHigh(i); } total = 0; } function runLow(i) { startCall(); t.dispatcher.queue = 'priority'; t.dispatcher.priority = 10; return t.echo_string('Not urgent, number ' + i + ' '); } function runHigh(i) { startCall(); t.dispatcher.queue = 'priority'; t.dispatcher.priority = 0; return t.echo_string('Urgent, number ' + i + ' '); } function startCall() { time1 = new Date(); } function endCall(name) { var time = 0; var time2 = new Date(); time = time2.getTime() - time1.getTime(); document.getElementById('target').innerHTML += name + "time: " + time + "<br>"; if (++count == 20) { document.getElementById('target').innerHTML += "Done<br>"; } } </script> </head> <body> <a href="javascript:priorityTest()">Start Priority Test</a> <div id="target"> </div> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/test_speed.php?view=markup&rev=1.1 Index: pear/HTML_AJAX/examples/tests/test_speed.php +++ pear/HTML_AJAX/examples/tests/test_speed.php <?php /** * Simple speed test using the null serializer, possibly useful in comparing overhead when tested on local host * * * @category HTML * @package AJAX * @author Joshua Eichorn <josh@bluga.net> * @copyright 2005 Joshua Eichorn * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version Release: @package_version@ * @link http://pear.php.net/package/HTML_AJAX */ include 'HTML/AJAX.php'; include '../support/test.class.php'; $ajax = new HTML_AJAX(); $ajax->serializer = "Null"; $ajax->unserializer = "Null"; $ajax->registerClass(new test()); if ($ajax->handleRequest()) { die(); } ?><html> <head> <script type='text/javascript' src="../server.php?client=all&stub=all"></script> </head> <body> <script type="text/javascript"> var t = new test(); var t2 = new test({echo_string: function(){ endCall('Async Echo'); totalA(); }}); var time1; var total = 0; var count = 0; function speedTest() { document.getElementById('target').innerHTML += "10 Sync Calls<br>"; for(var i = 0; i < 10; i++) { startCall(); t.echo_string('Test'); endCall('Sync Echo'); } document.getElementById('target').innerHTML += "Total: "+total+"<br><br><br>"; total = 0; document.getElementById('target').innerHTML += "10 Async Calls<br>"; count = 0; for(var i = 0; i < 10; i++) { setTimeout("runAsync();",500*i); } total = 0; } function totalA() { count++; if (count == 10) { document.getElementById('target').innerHTML += "Total: "+total+"<br>"; } } function runAsync() { startCall(); t2.echo_string('Test'); } function startCall() { time1 = new Date(); } function endCall(name) { var time = 0; var time2 = new Date(); time = time2.getTime() - time1.getTime(); total += time; document.getElementById('target').innerHTML += name+":"+time+"<br>"; } </script> <a href="javascript:speedTest()">Start Speed Test</a> <div id="target"> </div> </body> </html>
« previous php.pear.cvs (#42524) next »