3 * Benchamrking suite for the PHP-XMLRPC lib
4 * @author Gaetano Giunta
6 * @copyright (c) 2005-2008 G. Giunta
7 * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
10 include(getcwd().'/parse_args.php');
12 require_once('xmlrpc.inc');
14 // Set up PHP structures to be used in many tests
15 $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
16 $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
17 $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
18 $keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
20 $test_results=array();
21 $xd = extension_loaded('xdebug') && ini_get('xdebug.profiler_enable');
27 $title = 'XML-RPC Benchmark Tests';
29 if(isset($_SERVER['REQUEST_METHOD']))
31 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n<title>$title</title>\n</head>\n<body>\n<h1>$title</h1>\n<pre>\n";
38 if(isset($_SERVER['REQUEST_METHOD']))
40 echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
41 if ($xd) echo "<h4>XDEBUG profiling enabled: skipping remote tests. Trace file is: ".htmlspecialchars(xdebug_get_profiler_filename())."</h4>\n";
46 echo "Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."\n";
47 if ($xd) echo "XDEBUG profiling enabled: skipping remote tests\nTrace file is: ".xdebug_get_profiler_filename()."\n";
50 // test 'old style' data encoding vs. 'automatic style' encoding
51 begin_test('Data encoding (large array)', 'manual encoding');
52 for ($i = 0; $i < $num_tests; $i++)
55 for ($j = 0; $j < 10; $j++)
58 foreach ($data[$j] as $key => $val)
61 $values[] =& new xmlrpcval($val[0], 'int');
62 $values[] =& new xmlrpcval($val[1], 'double');
63 $values[] =& new xmlrpcval($val[2], 'string');
64 $values[] =& new xmlrpcval($val[3], 'boolean');
65 $values[] =& new xmlrpcval($val[4], 'dateTime.iso8601');
66 $values[] =& new xmlrpcval($val[5], 'i4');
67 $values[] =& new xmlrpcval($val[6], 'double');
68 $values[] =& new xmlrpcval($val[7], 'string');
69 $values[] =& new xmlrpcval($val[8], 'boolean');
70 $values[] =& new xmlrpcval($val[9], 'dateTime.iso8601');
71 $valarray[$key] =& new xmlrpcval($values, 'array');
73 $vals[] =& new xmlrpcval($valarray, 'struct');
75 $value =& new xmlrpcval($vals, 'array');
76 $out = $value->serialize();
78 end_test('Data encoding (large array)', 'manual encoding', $out);
80 begin_test('Data encoding (large array)', 'automatic encoding');
81 for ($i = 0; $i < $num_tests; $i++)
83 $value =& php_xmlrpc_encode($data, array('auto_dates'));
84 $out = $value->serialize();
86 end_test('Data encoding (large array)', 'automatic encoding', $out);
88 if (function_exists('xmlrpc_set_type'))
90 begin_test('Data encoding (large array)', 'xmlrpc-epi encoding');
91 for ($i = 0; $i < $num_tests; $i++)
93 for ($j = 0; $j < 10; $j++)
96 xmlrpc_set_type($data[$j][$k][4], 'datetime');
97 xmlrpc_set_type($data[$j][$k][8], 'datetime');
99 $out = xmlrpc_encode($data);
101 end_test('Data encoding (large array)', 'xmlrpc-epi encoding', $out);
104 // test 'old style' data decoding vs. 'automatic style' decoding
105 $dummy = new xmlrpcmsg('');
106 $out = new xmlrpcresp($value);
107 $in = '<?xml version="1.0" ?>'."\n".$out->serialize();
109 begin_test('Data decoding (large array)', 'manual decoding');
110 for ($i = 0; $i < $num_tests; $i++)
112 $response =& $dummy->ParseResponse($in, true);
113 $value = $response->value();
115 for ($k = 0; $k < $value->arraysize(); $k++)
117 $val1 = $value->arraymem($k);
119 while (list($name, $val) = $val1->structeach())
121 $out[$name] = array();
122 for ($j = 0; $j < $val->arraysize(); $j++)
124 $data = $val->arraymem($j);
125 $out[$name][] = $data->scalarval();
131 end_test('Data decoding (large array)', 'manual decoding', $result);
133 begin_test('Data decoding (large array)', 'automatic decoding');
134 for ($i = 0; $i < $num_tests; $i++)
136 $response =& $dummy->ParseResponse($in, true, 'phpvals');
137 $value = $response->value();
139 end_test('Data decoding (large array)', 'automatic decoding', $value);
141 if (function_exists('xmlrpc_decode'))
143 begin_test('Data decoding (large array)', 'xmlrpc-epi decoding');
144 for ($i = 0; $i < $num_tests; $i++)
146 $response =& $dummy->ParseResponse($in, true, 'xml');
147 $value = xmlrpc_decode($response->value());
149 end_test('Data decoding (large array)', 'xmlrpc-epi decoding', $value);
154 /// test multicall vs. many calls vs. keep-alives
155 $value = php_xmlrpc_encode($data1);
156 $msg =& new xmlrpcmsg('interopEchoTests.echoValue', array($value));
158 for ($i = 0; $i < 25; $i++)
160 $server = split(':', $LOCALSERVER);
161 if(count($server) > 1)
163 $c =& new xmlrpc_client($URI, $server[0], $server[1]);
167 $c =& new xmlrpc_client($URI, $LOCALSERVER);
169 // do not interfere with http compression
170 $c->accepted_compression = array();
173 if (function_exists('gzinflate')) {
174 $c->accepted_compression = null;
176 begin_test('Repeated send (small array)', 'http 10');
178 for ($i = 0; $i < 25; $i++)
180 $resp =& $c->send($msg);
181 $response[] = $resp->value();
183 end_test('Repeated send (small array)', 'http 10', $response);
185 if (function_exists('curl_init'))
187 begin_test('Repeated send (small array)', 'http 11 w. keep-alive');
189 for ($i = 0; $i < 25; $i++)
191 $resp =& $c->send($msg, 10, 'http11');
192 $response[] = $resp->value();
194 end_test('Repeated send (small array)', 'http 11 w. keep-alive', $response);
196 $c->keepalive = false;
197 begin_test('Repeated send (small array)', 'http 11');
199 for ($i = 0; $i < 25; $i++)
201 $resp =& $c->send($msg, 10, 'http11');
202 $response[] = $resp->value();
204 end_test('Repeated send (small array)', 'http 11', $response);
207 begin_test('Repeated send (small array)', 'multicall');
208 $response =& $c->send($msgs);
209 end_test('Repeated send (small array)', 'multicall', $response);
211 if (function_exists('gzinflate'))
213 $c->accepted_compression = array('gzip');
214 $c->request_compression = 'gzip';
216 begin_test('Repeated send (small array)', 'http 10 w. compression');
218 for ($i = 0; $i < 25; $i++)
220 $resp =& $c->send($msg);
221 $response[] = $resp->value();
223 end_test('Repeated send (small array)', 'http 10 w. compression', $response);
226 } // end of 'if no xdebug profiling'
228 function begin_test($test_name, $test_case)
230 global $test_results;
231 if (!isset($test_results[$test_name]))
232 $test_results[$test_name]=array();
233 $test_results[$test_name][$test_case] = array();
234 list($micro, $sec) = explode(' ', microtime());
235 $test_results[$test_name][$test_case]['time'] = $sec + $micro;
238 function end_test($test_name, $test_case, $test_result)
240 global $test_results;
241 list($micro, $sec) = explode(' ', microtime());
242 if (!isset($test_results[$test_name][$test_case]))
243 trigger_error('ending test that was not sterted');
244 $test_results[$test_name][$test_case]['time'] = $sec + $micro - $test_results[$test_name][$test_case]['time'];
245 $test_results[$test_name][$test_case]['result'] = $test_result;
252 foreach($test_results as $test => $results)
254 echo "\nTEST: $test\n";
255 foreach ($results as $case => $data)
256 echo " $case: {$data['time']} secs - Output data CRC: ".crc32(serialize($data['result']))."\n";
260 if(isset($_SERVER['REQUEST_METHOD']))
262 echo "\n</pre>\n</body>\n</html>\n";