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_once(__DIR__.'/../vendor/autoload.php');
13 include_once(__DIR__.'/../lib/xmlrpc.inc');
15 include(__DIR__.'/parse_args.php');
16 $args = argParser::getArgs();
18 function begin_test($test_name, $test_case)
21 if (!isset($test_results[$test_name]))
22 $test_results[$test_name]=array();
23 $test_results[$test_name][$test_case] = array();
24 $test_results[$test_name][$test_case]['time'] = microtime(true);
27 function end_test($test_name, $test_case, $test_result)
30 $end = microtime(true);
31 if (!isset($test_results[$test_name][$test_case]))
32 trigger_error('ending test that was not sterted');
33 $test_results[$test_name][$test_case]['time'] = $end - $test_results[$test_name][$test_case]['time'];
34 $test_results[$test_name][$test_case]['result'] = $test_result;
40 // Set up PHP structures to be used in many tests
42 $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
43 $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
44 $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
45 $keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
49 $test_results=array();
50 $is_web = isset($_SERVER['REQUEST_METHOD']);
51 $xd = extension_loaded('xdebug') && ini_get('xdebug.profiler_enable');
57 $title = 'XML-RPC Benchmark Tests';
61 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";
70 echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
71 if ($xd) echo "<h4>XDEBUG profiling enabled: skipping remote tests. Trace file is: ".htmlspecialchars(xdebug_get_profiler_filename())."</h4>\n";
77 echo "Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."\n";
78 if ($xd) echo "XDEBUG profiling enabled: skipping remote tests\nTrace file is: ".xdebug_get_profiler_filename()."\n";
81 // test 'old style' data encoding vs. 'automatic style' encoding
82 begin_test('Data encoding (large array)', 'manual encoding');
83 for ($i = 0; $i < $num_tests; $i++)
86 for ($j = 0; $j < 10; $j++)
89 foreach ($data[$j] as $key => $val)
92 $values[] = new xmlrpcval($val[0], 'int');
93 $values[] = new xmlrpcval($val[1], 'double');
94 $values[] = new xmlrpcval($val[2], 'string');
95 $values[] = new xmlrpcval($val[3], 'boolean');
96 $values[] = new xmlrpcval($val[4], 'dateTime.iso8601');
97 $values[] = new xmlrpcval($val[5], 'int');
98 $values[] = new xmlrpcval($val[6], 'double');
99 $values[] = new xmlrpcval($val[7], 'string');
100 $values[] = new xmlrpcval($val[8], 'boolean');
101 $values[] = new xmlrpcval($val[9], 'dateTime.iso8601');
102 $valarray[$key] = new xmlrpcval($values, 'array');
104 $vals[] = new xmlrpcval($valarray, 'struct');
106 $value = new xmlrpcval($vals, 'array');
107 $out = $value->serialize();
109 end_test('Data encoding (large array)', 'manual encoding', $out);
111 begin_test('Data encoding (large array)', 'automatic encoding');
112 for ($i = 0; $i < $num_tests; $i++)
114 $value = php_xmlrpc_encode($data, array('auto_dates'));
115 $out = $value->serialize();
117 end_test('Data encoding (large array)', 'automatic encoding', $out);
119 if (function_exists('xmlrpc_set_type'))
121 begin_test('Data encoding (large array)', 'xmlrpc-epi encoding');
122 for ($i = 0; $i < $num_tests; $i++)
124 for ($j = 0; $j < 10; $j++)
125 foreach ($keys as $k)
127 xmlrpc_set_type($data[$j][$k][4], 'datetime');
128 xmlrpc_set_type($data[$j][$k][8], 'datetime');
130 $out = xmlrpc_encode($data);
132 end_test('Data encoding (large array)', 'xmlrpc-epi encoding', $out);
135 // test 'old style' data decoding vs. 'automatic style' decoding
136 $dummy = new xmlrpcmsg('');
137 $out = new xmlrpcresp($value);
138 $in = '<?xml version="1.0" ?>'."\n".$out->serialize();
140 begin_test('Data decoding (large array)', 'manual decoding');
141 for ($i = 0; $i < $num_tests; $i++)
143 $response = $dummy->ParseResponse($in, true);
144 $value = $response->value();
146 for ($k = 0; $k < $value->arraysize(); $k++)
148 $val1 = $value->arraymem($k);
150 while (list($name, $val) = $val1->structeach())
152 $out[$name] = array();
153 for ($j = 0; $j < $val->arraysize(); $j++)
155 $data = $val->arraymem($j);
156 $out[$name][] = $data->scalarval();
162 end_test('Data decoding (large array)', 'manual decoding', $result);
164 begin_test('Data decoding (large array)', 'automatic decoding');
165 for ($i = 0; $i < $num_tests; $i++)
167 $response = $dummy->ParseResponse($in, true, 'phpvals');
168 $value = $response->value();
170 end_test('Data decoding (large array)', 'automatic decoding', $value);
172 if (function_exists('xmlrpc_decode'))
174 begin_test('Data decoding (large array)', 'xmlrpc-epi decoding');
175 for ($i = 0; $i < $num_tests; $i++)
177 $response = $dummy->ParseResponse($in, true, 'xml');
178 $value = xmlrpc_decode($response->value());
180 end_test('Data decoding (large array)', 'xmlrpc-epi decoding', $value);
186 /// test multicall vs. many calls vs. keep-alives
187 $value = php_xmlrpc_encode($data1, array('auto_dates'));
188 $msg = new xmlrpcmsg('interopEchoTests.echoValue', array($value));
190 for ($i = 0; $i < 25; $i++)
192 $server = explode(':', $args['LOCALSERVER']);
193 if(count($server) > 1)
195 $c = new xmlrpc_client($args['URI'], $server[0], $server[1]);
199 $c = new xmlrpc_client($args['URI'], $args['LOCALSERVER']);
201 // do not interfere with http compression
202 $c->accepted_compression = array();
205 if (function_exists('gzinflate')) {
206 $c->accepted_compression = null;
208 begin_test('Repeated send (small array)', 'http 10');
210 for ($i = 0; $i < 25; $i++)
212 $resp = $c->send($msg);
213 $response[] = $resp->value();
215 end_test('Repeated send (small array)', 'http 10', $response);
217 if (function_exists('curl_init'))
219 begin_test('Repeated send (small array)', 'http 11 w. keep-alive');
221 for ($i = 0; $i < 25; $i++)
223 $resp = $c->send($msg, 10, 'http11');
224 $response[] = $resp->value();
226 end_test('Repeated send (small array)', 'http 11 w. keep-alive', $response);
228 $c->keepalive = false;
229 begin_test('Repeated send (small array)', 'http 11');
231 for ($i = 0; $i < 25; $i++)
233 $resp = $c->send($msg, 10, 'http11');
234 $response[] = $resp->value();
236 end_test('Repeated send (small array)', 'http 11', $response);
239 begin_test('Repeated send (small array)', 'multicall');
240 $response = $c->send($msgs);
241 foreach ($response as $key =>& $val)
243 $val = $val->value();
245 end_test('Repeated send (small array)', 'multicall', $response);
247 if (function_exists('gzinflate'))
249 $c->accepted_compression = array('gzip');
250 $c->request_compression = 'gzip';
252 begin_test('Repeated send (small array)', 'http 10 w. compression');
254 for ($i = 0; $i < 25; $i++)
256 $resp = $c->send($msg);
257 $response[] = $resp->value();
259 end_test('Repeated send (small array)', 'http 10 w. compression', $response);
261 if (function_exists('curl_init'))
263 begin_test('Repeated send (small array)', 'http 11 w. keep-alive and compression');
265 for ($i = 0; $i < 25; $i++)
267 $resp = $c->send($msg, 10, 'http11');
268 $response[] = $resp->value();
270 end_test('Repeated send (small array)', 'http 11 w. keep-alive and compression', $response);
272 $c->keepalive = false;
273 begin_test('Repeated send (small array)', 'http 11 w. compression');
275 for ($i = 0; $i < 25; $i++)
277 $resp = $c->send($msg, 10, 'http11');
278 $response[] = $resp->value();
280 end_test('Repeated send (small array)', 'http 11 w. compression', $response);
283 begin_test('Repeated send (small array)', 'multicall w. compression');
284 $response = $c->send($msgs);
285 foreach ($response as $key =>& $val)
287 $val = $val->value();
289 end_test('Repeated send (small array)', 'multicall w. compression', $response);
292 } // end of 'if no xdebug profiling'
296 foreach($test_results as $test => $results)
298 echo "\nTEST: $test\n";
299 foreach ($results as $case => $data)
300 echo " $case: {$data['time']} secs - Output data CRC: ".crc32(serialize($data['result']))."\n";
306 echo "\n</pre>\n</body>\n</html>\n";