|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once __DIR__ . "/_prepend.php"; |
|
4
|
|
|
|
|
5
|
|
|
use PhpXmlRpc\Encoder; |
|
6
|
|
|
use PhpXmlRpc\Client; |
|
7
|
|
|
use PhpXmlRpc\PhpXmlRpc; |
|
8
|
|
|
use PhpXmlRpc\Request; |
|
9
|
|
|
use PhpXmlRpc\Response; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* A class taking advantage of cURL to send many requests in parallel (to a single server), for when the given server |
|
13
|
|
|
* does not support system.multicall method |
|
14
|
|
|
*/ |
|
15
|
|
|
class ParallelClient extends Client |
|
16
|
|
|
{ |
|
17
|
|
|
public function sendParallel($requests, $timeout = 0, $method = '') |
|
18
|
|
|
{ |
|
19
|
|
|
if ($method == '') { |
|
20
|
|
|
$method = $this->method; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/// @todo validate that $method can be handled by the current curl install |
|
24
|
|
|
|
|
25
|
|
|
$handles = array(); |
|
26
|
|
|
$curl = curl_multi_init(); |
|
27
|
|
|
|
|
28
|
|
|
foreach($requests as $k => $req) { |
|
29
|
|
|
$req->setDebug($this->debug); |
|
30
|
|
|
|
|
31
|
|
|
$handle = $this->prepareCurlHandle( |
|
32
|
|
|
$req, |
|
33
|
|
|
$this->server, |
|
34
|
|
|
$this->port, |
|
35
|
|
|
$timeout, |
|
36
|
|
|
$this->username, |
|
37
|
|
|
$this->password, |
|
38
|
|
|
$this->authtype, |
|
39
|
|
|
$this->cert, |
|
40
|
|
|
$this->certpass, |
|
41
|
|
|
$this->cacert, |
|
42
|
|
|
$this->cacertdir, |
|
43
|
|
|
$this->proxy, |
|
44
|
|
|
$this->proxyport, |
|
45
|
|
|
$this->proxy_user, |
|
46
|
|
|
$this->proxy_pass, |
|
47
|
|
|
$this->proxy_authtype, |
|
48
|
|
|
$method, |
|
49
|
|
|
false, |
|
50
|
|
|
$this->key, |
|
51
|
|
|
$this->keypass, |
|
52
|
|
|
$this->sslversion |
|
53
|
|
|
); |
|
54
|
|
|
curl_multi_add_handle($curl, $handle); |
|
|
|
|
|
|
55
|
|
|
$handles[$k] = $handle; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$running = 0; |
|
59
|
|
|
do { |
|
60
|
|
|
curl_multi_exec($curl, $running); |
|
|
|
|
|
|
61
|
|
|
} while($running > 0); |
|
62
|
|
|
|
|
63
|
|
|
$responses = array(); |
|
64
|
|
|
foreach($handles as $k => $h) { |
|
65
|
|
|
$responses[$k] = curl_multi_getcontent($handles[$k]); |
|
66
|
|
|
|
|
67
|
|
|
if ($this->debug > 1) { |
|
68
|
|
|
$message = "---CURL INFO---\n"; |
|
69
|
|
|
foreach (curl_getinfo($h) as $name => $val) { |
|
70
|
|
|
if (is_array($val)) { |
|
71
|
|
|
$val = implode("\n", $val); |
|
72
|
|
|
} |
|
73
|
|
|
$message .= $name . ': ' . $val . "\n"; |
|
74
|
|
|
} |
|
75
|
|
|
$message .= '---END---'; |
|
76
|
|
|
$this->getLogger()->debugMessage($message); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
//curl_close($h); |
|
80
|
|
|
curl_multi_remove_handle($curl, $h); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
curl_multi_close($curl); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
foreach($responses as $k => $resp) { |
|
85
|
|
|
if (!$resp) { |
|
86
|
|
|
$responses[$k] = new Response(0, PhpXmlRpc::$xmlrpcerr['curl_fail'], PhpXmlRpc::$xmlrpcstr['curl_fail'] . ': ' . curl_error($curl)); |
|
|
|
|
|
|
87
|
|
|
} else { |
|
88
|
|
|
$responses[$k] = $requests[$k]->parseResponse($resp, true, $this->return_type); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $responses; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$num_tests = 25; |
|
97
|
|
|
|
|
98
|
|
|
$data = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00'); |
|
99
|
|
|
$encoder = new Encoder(); |
|
100
|
|
|
$value = $encoder->encode($data, array('auto_dates')); |
|
101
|
|
|
$req = new Request('interopEchoTests.echoValue', array($value)); |
|
102
|
|
|
$reqs = array(); |
|
103
|
|
|
for ($i = 0; $i < $num_tests; $i++) { |
|
104
|
|
|
$reqs[] = $req; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$client = new ParallelClient(XMLRPCSERVER); |
|
108
|
|
|
$client->no_multicall = true; |
|
109
|
|
|
|
|
110
|
|
|
$t = microtime(true); |
|
111
|
|
|
$resp = $client->send($reqs); |
|
112
|
|
|
$t = microtime(true) - $t; |
|
113
|
|
|
echo "Sequential send: $t secs\n"; |
|
114
|
|
|
|
|
115
|
|
|
$t = microtime(true); |
|
116
|
|
|
$resp = $client->sendParallel($reqs); |
|
117
|
|
|
$t = microtime(true) - $t; |
|
118
|
|
|
echo "Parallel send: $t secs\n"; |
|
119
|
|
|
|
|
120
|
|
|
$client->no_multicall = false; |
|
121
|
|
|
$t = microtime(true); |
|
122
|
|
|
$resp = $client->send($reqs); |
|
123
|
|
|
$t = microtime(true) - $t; |
|
124
|
|
|
echo "Multicall send: $t secs\n"; |
|
125
|
|
|
|
|
126
|
|
|
require_once __DIR__ . "/_append.php"; |
|
127
|
|
|
|