3 * Benchamrking suite for the PHP-XMLRPC lib
4 * @author Gaetano Giunta
6 * @copyright (c) 2005-2009 G. Giunta
7 * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
9 * @todo add a test for response ok in call testing?
12 include(getcwd().'/parse_args.php');
14 require_once('xmlrpc.inc');
16 // Set up PHP structures to be used in many tests
17 $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
18 $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
19 $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
20 $keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
22 $test_results=array();
23 $xd = extension_loaded('xdebug') && ini_get('xdebug.profiler_enable');
29 $title = 'XML-RPC Benchmark Tests';
31 if(isset($_SERVER['REQUEST_METHOD']))
33 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";
40 if(isset($_SERVER['REQUEST_METHOD']))
42 echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
43 if ($xd) echo "<h4>XDEBUG profiling enabled: skipping remote tests. Trace file is: ".htmlspecialchars(xdebug_get_profiler_filename())."</h4>\n";
49 echo "Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."\n";
50 if ($xd) echo "XDEBUG profiling enabled: skipping remote tests\nTrace file is: ".xdebug_get_profiler_filename()."\n";
53 // test 'old style' data encoding vs. 'automatic style' encoding
54 begin_test('Data encoding (large array)', 'manual encoding');
55 for ($i = 0; $i < $num_tests; $i++)
58 for ($j = 0; $j < 10; $j++)
61 foreach ($data[$j] as $key => $val)
64 $values[] = new xmlrpcval($val[0], 'int');
65 $values[] = new xmlrpcval($val[1], 'double');
66 $values[] = new xmlrpcval($val[2], 'string');
67 $values[] = new xmlrpcval($val[3], 'boolean');
68 $values[] = new xmlrpcval($val[4], 'dateTime.iso8601');
69 $values[] = new xmlrpcval($val[5], 'int');
70 $values[] = new xmlrpcval($val[6], 'double');
71 $values[] = new xmlrpcval($val[7], 'string');
72 $values[] = new xmlrpcval($val[8], 'boolean');
73 $values[] = new xmlrpcval($val[9], 'dateTime.iso8601');
74 $valarray[$key] = new xmlrpcval($values, 'array');
76 $vals[] = new xmlrpcval($valarray, 'struct');
78 $value = new xmlrpcval($vals, 'array');
79 $out = $value->serialize();
81 end_test('Data encoding (large array)', 'manual encoding', $out);
83 begin_test('Data encoding (large array)', 'automatic encoding');
84 for ($i = 0; $i < $num_tests; $i++)
86 $value =& php_xmlrpc_encode($data, array('auto_dates'));
87 $out = $value->serialize();
89 end_test('Data encoding (large array)', 'automatic encoding', $out);
91 if (function_exists('xmlrpc_set_type'))
93 begin_test('Data encoding (large array)', 'xmlrpc-epi encoding');
94 for ($i = 0; $i < $num_tests; $i++)
96 for ($j = 0; $j < 10; $j++)
99 xmlrpc_set_type($data[$j][$k][4], 'datetime');
100 xmlrpc_set_type($data[$j][$k][8], 'datetime');
102 $out = xmlrpc_encode($data);
104 end_test('Data encoding (large array)', 'xmlrpc-epi encoding', $out);
107 // test 'old style' data decoding vs. 'automatic style' decoding
108 $dummy = new xmlrpcmsg('');
109 $out = new xmlrpcresp($value);
110 $in = '<?xml version="1.0" ?>'."\n".$out->serialize();
112 begin_test('Data decoding (large array)', 'manual decoding');
113 for ($i = 0; $i < $num_tests; $i++)
115 $response =& $dummy->ParseResponse($in, true);
116 $value = $response->value();
118 for ($k = 0; $k < $value->arraysize(); $k++)
120 $val1 = $value->arraymem($k);
122 while (list($name, $val) = $val1->structeach())
124 $out[$name] = array();
125 for ($j = 0; $j < $val->arraysize(); $j++)
127 $data = $val->arraymem($j);
128 $out[$name][] = $data->scalarval();
134 end_test('Data decoding (large array)', 'manual decoding', $result);
136 begin_test('Data decoding (large array)', 'automatic decoding');
137 for ($i = 0; $i < $num_tests; $i++)
139 $response =& $dummy->ParseResponse($in, true, 'phpvals');
140 $value = $response->value();
142 end_test('Data decoding (large array)', 'automatic decoding', $value);
144 if (function_exists('xmlrpc_decode'))
146 begin_test('Data decoding (large array)', 'xmlrpc-epi decoding');
147 for ($i = 0; $i < $num_tests; $i++)
149 $response =& $dummy->ParseResponse($in, true, 'xml');
150 $value = xmlrpc_decode($response->value());
152 end_test('Data decoding (large array)', 'xmlrpc-epi decoding', $value);
157 /// test multicall vs. many calls vs. keep-alives
158 $value = php_xmlrpc_encode($data1, array('auto_dates'));
159 $msg = new xmlrpcmsg('interopEchoTests.echoValue', array($value));
161 for ($i = 0; $i < 25; $i++)
163 $server = explode(':', $LOCALSERVER);
164 if(count($server) > 1)
166 $c = new xmlrpc_client($URI, $server[0], $server[1]);
170 $c = new xmlrpc_client($URI, $LOCALSERVER);
172 // do not interfere with http compression
173 $c->accepted_compression = array();
176 if (function_exists('gzinflate')) {
177 $c->accepted_compression = null;
179 begin_test('Repeated send (small array)', 'http 10');
181 for ($i = 0; $i < 25; $i++)
183 $resp =& $c->send($msg);
184 $response[] = $resp->value();
186 end_test('Repeated send (small array)', 'http 10', $response);
188 if (function_exists('curl_init'))
190 begin_test('Repeated send (small array)', 'http 11 w. keep-alive');
192 for ($i = 0; $i < 25; $i++)
194 $resp =& $c->send($msg, 10, 'http11');
195 $response[] = $resp->value();
197 end_test('Repeated send (small array)', 'http 11 w. keep-alive', $response);
199 $c->keepalive = false;
200 begin_test('Repeated send (small array)', 'http 11');
202 for ($i = 0; $i < 25; $i++)
204 $resp =& $c->send($msg, 10, 'http11');
205 $response[] = $resp->value();
207 end_test('Repeated send (small array)', 'http 11', $response);
210 begin_test('Repeated send (small array)', 'multicall');
211 $response =& $c->send($msgs);
212 foreach ($response as $key =>& $val)
214 $val = $val->value();
216 end_test('Repeated send (small array)', 'multicall', $response);
218 if (function_exists('gzinflate'))
220 $c->accepted_compression = array('gzip');
221 $c->request_compression = 'gzip';
223 begin_test('Repeated send (small array)', 'http 10 w. compression');
225 for ($i = 0; $i < 25; $i++)
227 $resp =& $c->send($msg);
228 $response[] = $resp->value();
230 end_test('Repeated send (small array)', 'http 10 w. compression', $response);
232 if (function_exists('curl_init'))
234 begin_test('Repeated send (small array)', 'http 11 w. keep-alive and compression');
236 for ($i = 0; $i < 25; $i++)
238 $resp =& $c->send($msg, 10, 'http11');
239 $response[] = $resp->value();
241 end_test('Repeated send (small array)', 'http 11 w. keep-alive and compression', $response);
243 $c->keepalive = false;
244 begin_test('Repeated send (small array)', 'http 11 w. compression');
246 for ($i = 0; $i < 25; $i++)
248 $resp =& $c->send($msg, 10, 'http11');
249 $response[] = $resp->value();
251 end_test('Repeated send (small array)', 'http 11 w. compression', $response);
254 begin_test('Repeated send (small array)', 'multicall w. compression');
255 $response =& $c->send($msgs);
256 foreach ($response as $key =>& $val)
258 $val = $val->value();
260 end_test('Repeated send (small array)', 'multicall w. compression', $response);
263 } // end of 'if no xdebug profiling'
265 function begin_test($test_name, $test_case)
267 global $test_results;
268 if (!isset($test_results[$test_name]))
269 $test_results[$test_name]=array();
270 $test_results[$test_name][$test_case] = array();
271 $test_results[$test_name][$test_case]['time'] = microtime(true);
274 function end_test($test_name, $test_case, $test_result)
276 global $test_results;
277 $end = microtime(true);
278 if (!isset($test_results[$test_name][$test_case]))
279 trigger_error('ending test that was not sterted');
280 $test_results[$test_name][$test_case]['time'] = $end - $test_results[$test_name][$test_case]['time'];
281 $test_results[$test_name][$test_case]['result'] = $test_result;
289 foreach($test_results as $test => $results)
291 echo "\nTEST: $test\n";
292 foreach ($results as $case => $data)
293 echo " $case: {$data['time']} secs - Output data CRC: ".crc32(serialize($data['result']))."\n";
297 if(isset($_SERVER['REQUEST_METHOD']))
299 echo "\n</pre>\n</body>\n</html>\n";