3 * Benchamrking suite for the PHP-XMLRPC lib
4 * @author Gaetano Giunta
5 * @copyright (c) 2005-2014 G. Giunta
6 * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
8 * @todo add a test for response ok in call testing?
11 include(dirname(__FILE__).'/parse_args.php');
13 require_once('xmlrpc.inc');
15 // Set up PHP structures to be used in many tests
16 $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
17 $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
18 $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
19 $keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
21 $test_results=array();
22 $xd = extension_loaded('xdebug') && ini_get('xdebug.profiler_enable');
28 $title = 'XML-RPC Benchmark Tests';
30 if(isset($_SERVER['REQUEST_METHOD']))
32 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";
39 if(isset($_SERVER['REQUEST_METHOD']))
41 echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
42 if ($xd) echo "<h4>XDEBUG profiling enabled: skipping remote tests. Trace file is: ".htmlspecialchars(xdebug_get_profiler_filename())."</h4>\n";
48 echo "Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."\n";
49 if ($xd) echo "XDEBUG profiling enabled: skipping remote tests\nTrace file is: ".xdebug_get_profiler_filename()."\n";
52 // test 'old style' data encoding vs. 'automatic style' encoding
53 begin_test('Data encoding (large array)', 'manual encoding');
54 for ($i = 0; $i < $num_tests; $i++)
57 for ($j = 0; $j < 10; $j++)
60 foreach ($data[$j] as $key => $val)
63 $values[] = new xmlrpcval($val[0], 'int');
64 $values[] = new xmlrpcval($val[1], 'double');
65 $values[] = new xmlrpcval($val[2], 'string');
66 $values[] = new xmlrpcval($val[3], 'boolean');
67 $values[] = new xmlrpcval($val[4], 'dateTime.iso8601');
68 $values[] = new xmlrpcval($val[5], 'int');
69 $values[] = new xmlrpcval($val[6], 'double');
70 $values[] = new xmlrpcval($val[7], 'string');
71 $values[] = new xmlrpcval($val[8], 'boolean');
72 $values[] = new xmlrpcval($val[9], 'dateTime.iso8601');
73 $valarray[$key] = new xmlrpcval($values, 'array');
75 $vals[] = new xmlrpcval($valarray, 'struct');
77 $value = new xmlrpcval($vals, 'array');
78 $out = $value->serialize();
80 end_test('Data encoding (large array)', 'manual encoding', $out);
82 begin_test('Data encoding (large array)', 'automatic encoding');
83 for ($i = 0; $i < $num_tests; $i++)
85 $value = php_xmlrpc_encode($data, array('auto_dates'));
86 $out = $value->serialize();
88 end_test('Data encoding (large array)', 'automatic encoding', $out);
90 if (function_exists('xmlrpc_set_type'))
92 begin_test('Data encoding (large array)', 'xmlrpc-epi encoding');
93 for ($i = 0; $i < $num_tests; $i++)
95 for ($j = 0; $j < 10; $j++)
98 xmlrpc_set_type($data[$j][$k][4], 'datetime');
99 xmlrpc_set_type($data[$j][$k][8], 'datetime');
101 $out = xmlrpc_encode($data);
103 end_test('Data encoding (large array)', 'xmlrpc-epi encoding', $out);
106 // test 'old style' data decoding vs. 'automatic style' decoding
107 $dummy = new xmlrpcmsg('');
108 $out = new xmlrpcresp($value);
109 $in = '<?xml version="1.0" ?>'."\n".$out->serialize();
111 begin_test('Data decoding (large array)', 'manual decoding');
112 for ($i = 0; $i < $num_tests; $i++)
114 $response =& $dummy->ParseResponse($in, true);
115 $value = $response->value();
117 for ($k = 0; $k < $value->arraysize(); $k++)
119 $val1 = $value->arraymem($k);
121 while (list($name, $val) = $val1->structeach())
123 $out[$name] = array();
124 for ($j = 0; $j < $val->arraysize(); $j++)
126 $data = $val->arraymem($j);
127 $out[$name][] = $data->scalarval();
133 end_test('Data decoding (large array)', 'manual decoding', $result);
135 begin_test('Data decoding (large array)', 'automatic decoding');
136 for ($i = 0; $i < $num_tests; $i++)
138 $response =& $dummy->ParseResponse($in, true, 'phpvals');
139 $value = $response->value();
141 end_test('Data decoding (large array)', 'automatic decoding', $value);
143 if (function_exists('xmlrpc_decode'))
145 begin_test('Data decoding (large array)', 'xmlrpc-epi decoding');
146 for ($i = 0; $i < $num_tests; $i++)
148 $response =& $dummy->ParseResponse($in, true, 'xml');
149 $value = xmlrpc_decode($response->value());
151 end_test('Data decoding (large array)', 'xmlrpc-epi decoding', $value);
156 /// test multicall vs. many calls vs. keep-alives
157 $value = php_xmlrpc_encode($data1, array('auto_dates'));
158 $msg = new xmlrpcmsg('interopEchoTests.echoValue', array($value));
160 for ($i = 0; $i < 25; $i++)
162 $server = explode(':', $LOCALSERVER);
163 if(count($server) > 1)
165 $c = new xmlrpc_client($URI, $server[0], $server[1]);
169 $c = new xmlrpc_client($URI, $LOCALSERVER);
171 // do not interfere with http compression
172 $c->accepted_compression = array();
175 if (function_exists('gzinflate')) {
176 $c->accepted_compression = null;
178 begin_test('Repeated send (small array)', 'http 10');
180 for ($i = 0; $i < 25; $i++)
182 $resp =& $c->send($msg);
183 $response[] = $resp->value();
185 end_test('Repeated send (small array)', 'http 10', $response);
187 if (function_exists('curl_init'))
189 begin_test('Repeated send (small array)', 'http 11 w. keep-alive');
191 for ($i = 0; $i < 25; $i++)
193 $resp =& $c->send($msg, 10, 'http11');
194 $response[] = $resp->value();
196 end_test('Repeated send (small array)', 'http 11 w. keep-alive', $response);
198 $c->keepalive = false;
199 begin_test('Repeated send (small array)', 'http 11');
201 for ($i = 0; $i < 25; $i++)
203 $resp =& $c->send($msg, 10, 'http11');
204 $response[] = $resp->value();
206 end_test('Repeated send (small array)', 'http 11', $response);
209 begin_test('Repeated send (small array)', 'multicall');
210 $response =& $c->send($msgs);
211 foreach ($response as $key =>& $val)
213 $val = $val->value();
215 end_test('Repeated send (small array)', 'multicall', $response);
217 if (function_exists('gzinflate'))
219 $c->accepted_compression = array('gzip');
220 $c->request_compression = 'gzip';
222 begin_test('Repeated send (small array)', 'http 10 w. compression');
224 for ($i = 0; $i < 25; $i++)
226 $resp =& $c->send($msg);
227 $response[] = $resp->value();
229 end_test('Repeated send (small array)', 'http 10 w. compression', $response);
231 if (function_exists('curl_init'))
233 begin_test('Repeated send (small array)', 'http 11 w. keep-alive and compression');
235 for ($i = 0; $i < 25; $i++)
237 $resp =& $c->send($msg, 10, 'http11');
238 $response[] = $resp->value();
240 end_test('Repeated send (small array)', 'http 11 w. keep-alive and compression', $response);
242 $c->keepalive = false;
243 begin_test('Repeated send (small array)', 'http 11 w. compression');
245 for ($i = 0; $i < 25; $i++)
247 $resp =& $c->send($msg, 10, 'http11');
248 $response[] = $resp->value();
250 end_test('Repeated send (small array)', 'http 11 w. compression', $response);
253 begin_test('Repeated send (small array)', 'multicall w. compression');
254 $response =& $c->send($msgs);
255 foreach ($response as $key =>& $val)
257 $val = $val->value();
259 end_test('Repeated send (small array)', 'multicall w. compression', $response);
262 } // end of 'if no xdebug profiling'
264 function begin_test($test_name, $test_case)
266 global $test_results;
267 if (!isset($test_results[$test_name]))
268 $test_results[$test_name]=array();
269 $test_results[$test_name][$test_case] = array();
270 $test_results[$test_name][$test_case]['time'] = microtime(true);
273 function end_test($test_name, $test_case, $test_result)
275 global $test_results;
276 $end = microtime(true);
277 if (!isset($test_results[$test_name][$test_case]))
278 trigger_error('ending test that was not sterted');
279 $test_results[$test_name][$test_case]['time'] = $end - $test_results[$test_name][$test_case]['time'];
280 $test_results[$test_name][$test_case]['result'] = $test_result;
288 foreach($test_results as $test => $results)
290 echo "\nTEST: $test\n";
291 foreach ($results as $case => $data)
292 echo " $case: {$data['time']} secs - Output data CRC: ".crc32(serialize($data['result']))."\n";
296 if(isset($_SERVER['REQUEST_METHOD']))
298 echo "\n</pre>\n</body>\n</html>\n";