7 /// @todo: do these need to be public?
11 public $method='http';
24 public $verifypeer=true;
26 public $no_multicall=false;
29 public $proxy_user='';
30 public $proxy_pass='';
31 public $proxy_authtype=1;
32 public $cookies=array();
33 public $extracurlopts=array();
36 * List of http compression methods accepted by the client for responses.
37 * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
39 * NNB: you can set it to any non-empty array for HTTP11 and HTTPS, since
40 * in those cases it will be up to CURL to decide the compression methods
41 * it supports. You might check for the presence of 'zlib' in the output of
42 * curl_version() to determine wheter compression is supported or not
44 public $accepted_compression = array();
46 * Name of compression scheme to be used for sending requests.
47 * Either null, gzip or deflate
49 public $request_compression = '';
51 * CURL handle: used for keep-alive connections (PHP 4.3.8 up, see:
52 * http://curl.haxx.se/docs/faq.html#7.3)
54 public $xmlrpc_curl_handle = null;
55 /// Whether to use persistent connections for http 1.1 and https
56 public $keepalive = false;
57 /// Charset encodings that can be decoded without problems by the client
58 public $accepted_charset_encodings = array();
59 /// Charset encoding to be used in serializing request. NULL = use ASCII
60 public $request_charset_encoding = '';
62 * Decides the content of Response objects returned by calls to send()
63 * valid strings are 'xmlrpcvals', 'phpvals' or 'xml'
65 public $return_type = 'xmlrpcvals';
67 * Sent to servers in http headers
72 * @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php
73 * @param string $server the server name / ip address
74 * @param integer $port the port the server is listening on, defaults to 80 or 443 depending on protocol used
75 * @param string $method the http protocol variant: defaults to 'http', 'https' and 'http11' can be used if CURL is installed
77 function __construct($path, $server='', $port='', $method='')
79 // allow user to specify all params in $path
80 if($server == '' and $port == '' and $method == '')
82 $parts = parse_url($path);
83 $server = $parts['host'];
84 $path = isset($parts['path']) ? $parts['path'] : '';
85 if(isset($parts['query']))
87 $path .= '?'.$parts['query'];
89 if(isset($parts['fragment']))
91 $path .= '#'.$parts['fragment'];
93 if(isset($parts['port']))
95 $port = $parts['port'];
97 if(isset($parts['scheme']))
99 $method = $parts['scheme'];
101 if(isset($parts['user']))
103 $this->username = $parts['user'];
105 if(isset($parts['pass']))
107 $this->password = $parts['pass'];
110 if($path == '' || $path[0] != '/')
112 $this->path='/'.$path;
118 $this->server=$server;
125 $this->method=$method;
128 // if ZLIB is enabled, let the client by default accept compressed responses
129 if(function_exists('gzinflate') || (
130 function_exists('curl_init') && (($info = curl_version()) &&
131 ((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
134 $this->accepted_compression = array('gzip', 'deflate');
137 // keepalives: enabled by default
138 $this->keepalive = true;
140 // by default the xml parser can support these 3 charset encodings
141 $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
143 // initialize user_agent string
144 $this->user_agent = PhpXmlRpc::$xmlrpcName . ' ' . PhpXmlRpc::$xmlrpcVersion;
148 * Enables/disables the echoing to screen of the xmlrpc responses received
149 * @param integer $in values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)
151 public function setDebug($in)
157 * Add some http BASIC AUTH credentials, used by the client to authenticate
158 * @param string $u username
159 * @param string $p password
160 * @param integer $t auth type. See curl_setopt man page for supported auth types. Defaults to CURLAUTH_BASIC (basic auth)
162 public function setCredentials($u, $p, $t=1)
170 * Add a client-side https certificate
171 * @param string $cert
172 * @param string $certpass
174 public function setCertificate($cert, $certpass)
177 $this->certpass = $certpass;
181 * Add a CA certificate to verify server with (see man page about
182 * CURLOPT_CAINFO for more details)
183 * @param string $cacert certificate file name (or dir holding certificates)
184 * @param bool $is_dir set to true to indicate cacert is a dir. defaults to false
186 public function setCaCertificate($cacert, $is_dir=false)
190 $this->cacertdir = $cacert;
194 $this->cacert = $cacert;
199 * Set attributes for SSL communication: private SSL key
200 * NB: does not work in older php/curl installs
201 * Thanks to Daniel Convissor
202 * @param string $key The name of a file containing a private SSL key
203 * @param string $keypass The secret password needed to use the private SSL key
205 public function setKey($key, $keypass)
208 $this->keypass = $keypass;
212 * Set attributes for SSL communication: verify server certificate
213 * @param bool $i enable/disable verification of peer certificate
215 public function setSSLVerifyPeer($i)
217 $this->verifypeer = $i;
221 * Set attributes for SSL communication: verify match of server cert w. hostname
224 public function setSSLVerifyHost($i)
226 $this->verifyhost = $i;
231 * @param string $proxyhost
232 * @param string $proxyport Defaults to 8080 for HTTP and 443 for HTTPS
233 * @param string $proxyusername Leave blank if proxy has public access
234 * @param string $proxypassword Leave blank if proxy has public access
235 * @param int $proxyauthtype set to constant CURLAUTH_NTLM to use NTLM auth with proxy
237 public function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1)
239 $this->proxy = $proxyhost;
240 $this->proxyport = $proxyport;
241 $this->proxy_user = $proxyusername;
242 $this->proxy_pass = $proxypassword;
243 $this->proxy_authtype = $proxyauthtype;
247 * Enables/disables reception of compressed xmlrpc responses.
248 * Note that enabling reception of compressed responses merely adds some standard
249 * http headers to xmlrpc requests. It is up to the xmlrpc server to return
250 * compressed responses when receiving such requests.
251 * @param string $compmethod either 'gzip', 'deflate', 'any' or ''
253 public function setAcceptedCompression($compmethod)
255 if ($compmethod == 'any')
256 $this->accepted_compression = array('gzip', 'deflate');
258 if ($compmethod == false )
259 $this->accepted_compression = array();
261 $this->accepted_compression = array($compmethod);
265 * Enables/disables http compression of xmlrpc request.
266 * Take care when sending compressed requests: servers might not support them
267 * (and automatic fallback to uncompressed requests is not yet implemented)
268 * @param string $compmethod either 'gzip', 'deflate' or ''
270 public function setRequestCompression($compmethod)
272 $this->request_compression = $compmethod;
276 * Adds a cookie to list of cookies that will be sent to server.
277 * NB: setting any param but name and value will turn the cookie into a 'version 1' cookie:
278 * do not do it unless you know what you are doing
279 * @param string $name
280 * @param string $value
281 * @param string $path
282 * @param string $domain
285 * @todo check correctness of urlencoding cookie value (copied from php way of doing it...)
287 public function setCookie($name, $value='', $path='', $domain='', $port=null)
289 $this->cookies[$name]['value'] = urlencode($value);
290 if ($path || $domain || $port)
292 $this->cookies[$name]['path'] = $path;
293 $this->cookies[$name]['domain'] = $domain;
294 $this->cookies[$name]['port'] = $port;
295 $this->cookies[$name]['version'] = 1;
299 $this->cookies[$name]['version'] = 0;
304 * Directly set cURL options, for extra flexibility
305 * It allows eg. to bind client to a specific IP interface / address
306 * @param array $options
308 function SetCurlOptions( $options )
310 $this->extracurlopts = $options;
314 * Set user-agent string that will be used by this client instance
315 * in http headers sent to the server
317 function SetUserAgent( $agentstring )
319 $this->user_agent = $agentstring;
323 * Send an xmlrpc request
324 * @param mixed $msg The request object, or an array of requests for using multicall, or the complete xml representation of a request
325 * @param integer $timeout Connection timeout, in seconds, If unspecified, a platform specific timeout will apply
326 * @param string $method if left unspecified, the http protocol chosen during creation of the object will be used
329 public function& send($msg, $timeout=0, $method='')
331 // if user deos not specify http protocol, use native method of this client
332 // (i.e. method set during call to constructor)
335 $method = $this->method;
340 // $msg is an array of Requests
341 $r = $this->multicall($msg, $timeout, $method);
344 elseif(is_string($msg))
346 $n = new Message('');
351 // where msg is a Request
352 $msg->debug=$this->debug;
354 if($method == 'https')
356 $r = $this->sendPayloadHTTPS(
372 $this->proxy_authtype,
378 elseif($method == 'http11')
380 $r = $this->sendPayloadCURL(
396 $this->proxy_authtype,
403 $r = $this->sendPayloadHTTP10(
415 $this->proxy_authtype
422 private function sendPayloadHTTP10($msg, $server, $port, $timeout=0,
423 $username='', $password='', $authtype=1, $proxyhost='',
424 $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1)
431 // Only create the payload if it was not created previously
432 if(empty($msg->payload))
434 $msg->createPayload($this->request_charset_encoding);
437 $payload = $msg->payload;
438 // Deflate request body and set appropriate request headers
439 if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
441 if($this->request_compression == 'gzip')
443 $a = @gzencode($payload);
447 $encoding_hdr = "Content-Encoding: gzip\r\n";
452 $a = @gzcompress($payload);
456 $encoding_hdr = "Content-Encoding: deflate\r\n";
465 // thanks to Grant Rauscher <grant7@firstworld.net> for this
469 $credentials='Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
472 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported with HTTP 1.0');
476 $accepted_encoding = '';
477 if(is_array($this->accepted_compression) && count($this->accepted_compression))
479 $accepted_encoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n";
482 $proxy_credentials = '';
489 $connectserver = $proxyhost;
490 $connectport = $proxyport;
491 $uri = 'http://'.$server.':'.$port.$this->path;
492 if($proxyusername != '')
494 if ($proxyauthtype != 1)
496 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported with HTTP 1.0');
498 $proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername.':'.$proxypassword) . "\r\n";
503 $connectserver = $server;
504 $connectport = $port;
508 // Cookie generation, as per rfc2965 (version 1 cookies) or
509 // netscape's rules (version 0 cookies)
511 if (count($this->cookies))
514 foreach ($this->cookies as $name => $cookie)
516 if ($cookie['version'])
518 $version = ' $Version="' . $cookie['version'] . '";';
519 $cookieheader .= ' ' . $name . '="' . $cookie['value'] . '";';
521 $cookieheader .= ' $Path="' . $cookie['path'] . '";';
522 if ($cookie['domain'])
523 $cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
525 $cookieheader .= ' $Port="' . $cookie['port'] . '";';
529 $cookieheader .= ' ' . $name . '=' . $cookie['value'] . ";";
532 $cookieheader = 'Cookie:' . $version . substr($cookieheader, 0, -1) . "\r\n";
536 $port = ($port == 80) ? '' : (':' . $port);
538 $op= 'POST ' . $uri. " HTTP/1.0\r\n" .
539 'User-Agent: ' . $this->user_agent . "\r\n" .
540 'Host: '. $server . $port . "\r\n" .
545 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" .
547 'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " .
548 strlen($payload) . "\r\n\r\n" .
553 print "<PRE>\n---SENDING---\n" . htmlentities($op) . "\n---END---\n</PRE>";
554 // let the client see this now in case http times out...
560 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
564 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
568 if($timeout>0 && function_exists('stream_set_timeout'))
570 stream_set_timeout($fp, $timeout);
575 $this->errstr='Connect error: '.$this->errstr;
576 $r=new Response(0, PhpXmlRpc::$xmlrpcerr['http_error'], $this->errstr . ' (' . $this->errno . ')');
580 if(!fputs($fp, $op, strlen($op)))
583 $this->errstr='Write error';
584 $r=new Response(0, PhpXmlRpc::$xmlrpcerr['http_error'], $this->errstr);
589 // reset errno and errstr on successful socket connection
592 // G. Giunta 2005/10/24: close socket before parsing.
593 // should yield slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)
597 // shall we check for $data === FALSE?
598 // as per the manual, it signals an error
599 $ipd.=fread($fp, 32768);
602 $r = $msg->parseResponse($ipd, false, $this->return_type);
607 private function sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',
608 $password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',
609 $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1,
610 $keepalive=false, $key='', $keypass='')
612 $r = $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
613 $password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,
614 $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
619 * Contributed by Justin Miller <justin@voxel.net>
620 * Requires curl to be built into PHP
621 * NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers!
623 private function sendPayloadCURL($msg, $server, $port, $timeout=0, $username='',
624 $password='', $authtype=1, $cert='', $certpass='', $cacert='', $cacertdir='',
625 $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $method='https',
626 $keepalive=false, $key='', $keypass='')
628 if(!function_exists('curl_init'))
630 $this->errstr='CURL unavailable on this install';
631 $r=new Response(0, PhpXmlRpc::$xmlrpcerr['no_curl'], PhpXmlRpc::$xmlrpcstr['no_curl']);
634 if($method == 'https')
636 if(($info = curl_version()) &&
637 ((is_string($info) && strpos($info, 'OpenSSL') === null) || (is_array($info) && !isset($info['ssl_version']))))
639 $this->errstr='SSL unavailable on this install';
640 $r=new Response(0, PhpXmlRpc::$xmlrpcerr['no_ssl'], PhpXmlRpc::$xmlrpcstr['no_ssl']);
647 if($method == 'http')
657 // Only create the payload if it was not created previously
658 if(empty($msg->payload))
660 $msg->createPayload($this->request_charset_encoding);
663 // Deflate request body and set appropriate request headers
664 $payload = $msg->payload;
665 if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
667 if($this->request_compression == 'gzip')
669 $a = @gzencode($payload);
673 $encoding_hdr = 'Content-Encoding: gzip';
678 $a = @gzcompress($payload);
682 $encoding_hdr = 'Content-Encoding: deflate';
693 print "<PRE>\n---SENDING---\n" . htmlentities($payload) . "\n---END---\n</PRE>";
694 // let the client see this now in case http times out...
698 if(!$keepalive || !$this->xmlrpc_curl_handle)
700 $curl = curl_init($method . '://' . $server . ':' . $port . $this->path);
703 $this->xmlrpc_curl_handle = $curl;
708 $curl = $this->xmlrpc_curl_handle;
711 // results into variable
712 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
716 curl_setopt($curl, CURLOPT_VERBOSE, 1);
718 curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
719 // required for XMLRPC: post the data
720 curl_setopt($curl, CURLOPT_POST, 1);
722 curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
724 // return the header too
725 curl_setopt($curl, CURLOPT_HEADER, 1);
727 // NB: if we set an empty string, CURL will add http header indicating
728 // ALL methods it is supporting. This is possibly a better option than
729 // letting the user tell what curl can / cannot do...
730 if(is_array($this->accepted_compression) && count($this->accepted_compression))
732 //curl_setopt($curl, CURLOPT_ENCODING, implode(',', $this->accepted_compression));
733 // empty string means 'any supported by CURL' (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
734 if (count($this->accepted_compression) == 1)
736 curl_setopt($curl, CURLOPT_ENCODING, $this->accepted_compression[0]);
739 curl_setopt($curl, CURLOPT_ENCODING, '');
742 $headers = array('Content-Type: ' . $msg->content_type , 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
743 // if no keepalive is wanted, let the server know it in advance
746 $headers[] = 'Connection: close';
748 // request compression header
751 $headers[] = $encoding_hdr;
754 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
758 curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
761 if($username && $password)
763 curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
764 if (defined('CURLOPT_HTTPAUTH'))
766 curl_setopt($curl, CURLOPT_HTTPAUTH, $authtype);
768 else if ($authtype != 1)
770 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported by the current PHP/curl install');
774 if($method == 'https')
779 curl_setopt($curl, CURLOPT_SSLCERT, $cert);
784 curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certpass);
786 // whether to verify remote host's cert
787 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
788 // set ca certificates file/dir
791 curl_setopt($curl, CURLOPT_CAINFO, $cacert);
795 curl_setopt($curl, CURLOPT_CAPATH, $cacertdir);
797 // set key file (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
800 curl_setopt($curl, CURLOPT_SSLKEY, $key);
802 // set key password (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
805 curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keypass);
807 // whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used
808 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
816 $proxyport = 8080; // NB: even for HTTPS, local connection is on port 8080
818 curl_setopt($curl, CURLOPT_PROXY, $proxyhost.':'.$proxyport);
819 //curl_setopt($curl, CURLOPT_PROXYPORT,$proxyport);
822 curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername.':'.$proxypassword);
823 if (defined('CURLOPT_PROXYAUTH'))
825 curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype);
827 else if ($proxyauthtype != 1)
829 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
834 // NB: should we build cookie http headers by hand rather than let CURL do it?
835 // the following code does not honour 'expires', 'path' and 'domain' cookie attributes
836 // set to client obj the the user...
837 if (count($this->cookies))
840 foreach ($this->cookies as $name => $cookie)
842 $cookieheader .= $name . '=' . $cookie['value'] . '; ';
844 curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2));
847 foreach ($this->extracurlopts as $opt => $val)
849 curl_setopt($curl, $opt, $val);
852 $result = curl_exec($curl);
854 if ($this->debug > 1)
856 print "<PRE>\n---CURL INFO---\n";
857 foreach(curl_getinfo($curl) as $name => $val)
861 $val = implode("\n", $val);
863 print $name . ': ' . htmlentities($val) . "\n";
866 print "---END---\n</PRE>";
869 if(!$result) /// @todo we should use a better check here - what if we get back '' or '0'?
871 $this->errstr='no response';
872 $resp=new Response(0, PhpXmlRpc::$xmlrpcerr['curl_fail'], PhpXmlRpc::$xmlrpcstr['curl_fail']. ': '. curl_error($curl));
876 $this->xmlrpc_curl_handle = null;
885 $resp = $msg->parseResponse($result, true, $this->return_type);
886 // if we got back a 302, we can not reuse the curl handle for later calls
887 if($resp->faultCode() == PhpXmlRpc::$xmlrpcerr['http_error'] && $keepalive)
890 $this->xmlrpc_curl_handle = null;
897 * Send an array of requests and return an array of responses.
898 * Unless $this->no_multicall has been set to true, it will try first
899 * to use one single xmlrpc call to server method system.multicall, and
900 * revert to sending many successive calls in case of failure.
901 * This failure is also stored in $this->no_multicall for subsequent calls.
902 * Unfortunately, there is no server error code universally used to denote
903 * the fact that multicall is unsupported, so there is no way to reliably
904 * distinguish between that and a temporary failure.
905 * If you are sure that server supports multicall and do not want to
906 * fallback to using many single calls, set the fourth parameter to FALSE.
908 * NB: trying to shoehorn extra functionality into existing syntax has resulted
909 * in pretty much convoluted code...
911 * @param Request[] $msgs an array of Request objects
912 * @param integer $timeout connection timeout (in seconds)
913 * @param string $method the http protocol variant to be used
914 * @param boolean fallback When true, upon receiving an error during multicall, multiple single calls will be attempted
917 public function multicall($msgs, $timeout=0, $method='', $fallback=true)
921 $method = $this->method;
923 if(!$this->no_multicall)
925 $results = $this->_try_multicall($msgs, $timeout, $method);
926 if(is_array($results))
928 // System.multicall succeeded
933 // either system.multicall is unsupported by server,
934 // or call failed for some other reason.
937 // Don't try it next time...
938 $this->no_multicall = true;
942 if (is_a($results, '\PhpXmlRpc\Response'))
948 $result = new Response(0, PhpXmlRpc::$xmlrpcerr['multicall_error'], PhpXmlRpc::$xmlrpcstr['multicall_error']);
955 // override fallback, in case careless user tries to do two
956 // opposite things at the same time
963 // system.multicall is (probably) unsupported by server:
964 // emulate multicall via multiple requests
965 foreach($msgs as $msg)
967 $results[] = $this->send($msg, $timeout, $method);
972 // user does NOT want to fallback on many single calls:
973 // since we should always return an array of responses,
974 // return an array with the same error repeated n times
975 foreach($msgs as $msg)
977 $results[] = $result;
984 * Attempt to boxcar $msgs via system.multicall.
985 * Returns either an array of xmlrpcreponses, an xmlrpc error response
986 * or false (when received response does not respect valid multicall syntax)
988 private function _try_multicall($msgs, $timeout, $method)
990 // Construct multicall request
992 foreach($msgs as $msg)
994 $call['methodName'] = new Value($msg->method(),'string');
995 $numParams = $msg->getNumParams();
997 for($i = 0; $i < $numParams; $i++)
999 $params[$i] = $msg->getParam($i);
1001 $call['params'] = new Value($params, 'array');
1002 $calls[] = new Value($call, 'struct');
1004 $multicall = new Request('system.multicall');
1005 $multicall->addParam(new Value($calls, 'array'));
1008 $result = $this->send($multicall, $timeout, $method);
1010 if($result->faultCode() != 0)
1012 // call to system.multicall failed
1016 // Unpack responses.
1017 $rets = $result->value();
1019 if ($this->return_type == 'xml')
1023 else if ($this->return_type == 'phpvals')
1025 ///@todo test this code branch...
1026 $rets = $result->value();
1027 if(!is_array($rets))
1029 return false; // bad return type from system.multicall
1031 $numRets = count($rets);
1032 if($numRets != count($msgs))
1034 return false; // wrong number of return values.
1037 $response = array();
1038 for($i = 0; $i < $numRets; $i++)
1041 if (!is_array($val)) {
1049 return false; // Bad value
1051 // Normal return value
1052 $response[$i] = new Response($val[0], 0, '', 'phpvals');
1055 /// @todo remove usage of @: it is apparently quite slow
1056 $code = @$val['faultCode'];
1061 $str = @$val['faultString'];
1062 if(!is_string($str))
1066 $response[$i] = new Response(0, $code, $str);
1074 else // return type == 'xmlrpcvals'
1076 $rets = $result->value();
1077 if($rets->kindOf() != 'array')
1079 return false; // bad return type from system.multicall
1081 $numRets = $rets->arraysize();
1082 if($numRets != count($msgs))
1084 return false; // wrong number of return values.
1087 $response = array();
1088 for($i = 0; $i < $numRets; $i++)
1090 $val = $rets->arraymem($i);
1091 switch($val->kindOf())
1094 if($val->arraysize() != 1)
1096 return false; // Bad value
1098 // Normal return value
1099 $response[$i] = new Response($val->arraymem(0));
1102 $code = $val->structmem('faultCode');
1103 if($code->kindOf() != 'scalar' || $code->scalartyp() != 'int')
1107 $str = $val->structmem('faultString');
1108 if($str->kindOf() != 'scalar' || $str->scalartyp() != 'string')
1112 $response[$i] = new Response(0, $code->scalarval(), $str->scalarval());