Skip to content

Commit d6bcdaf

Browse files
committed
- Patch #7458 by chx: merged the XML-RPC multicall support into xmlrpc() and use lazy-loading for the XML-RPC libraries.(performance improvement).
1 parent 05014a3 commit d6bcdaf

3 files changed

Lines changed: 43 additions & 43 deletions

File tree

‎includes/common.inc‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,34 @@ function drupal_implode_autocomplete($array) {
18261826
return implode('||', $output);
18271827
}
18281828

1829+
/**
1830+
* Performs one or more XML-RPC request(s).
1831+
*
1832+
* @param $url
1833+
* An absolute URL of the XML-RPC endpoint.
1834+
* Example:
1835+
* http://www.domain.com/xmlrpc.php
1836+
* @param ...
1837+
* For one request:
1838+
* The method name followed by a variable number of arguments to the method.
1839+
* For multiple requests (system.multicall):
1840+
* An array of call arrays. Each call array follows the pattern of the single
1841+
* request: method name followed by the arguments to the method.
1842+
* @return
1843+
* For one request:
1844+
* Either the return value of the method on success, or FALSE.
1845+
* If FALSE is returned, see xmlrpc_errno() and xmlrpc_error_msg().
1846+
* For multiple requests:
1847+
* An array of results. Each result will either be the result
1848+
* returned by the method called, or an xmlrpc_error object if the call
1849+
* failed. See xmlrpc_error().
1850+
*/
1851+
function xmlrpc($url) {
1852+
require_once './includes/xmlrpc.inc';
1853+
$args = func_get_args();
1854+
return call_user_func_array('_xmlrpc', $args);
1855+
}
1856+
18291857
function _drupal_bootstrap_full() {
18301858
static $called;
18311859
global $locale;
@@ -1840,7 +1868,6 @@ function _drupal_bootstrap_full() {
18401868
require_once './includes/tablesort.inc';
18411869
require_once './includes/file.inc';
18421870
require_once './includes/unicode.inc';
1843-
require_once './includes/xmlrpc.inc';
18441871
require_once './includes/image.inc';
18451872
// Set the Drupal custom error handler.
18461873
set_error_handler('error_handler');

‎includes/xmlrpc.inc‎

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -340,25 +340,21 @@ function xmlrpc_base64_get_xml($xmlrpc_base64) {
340340
return '<base64>'. base64_encode($xmlrpc_base64->data) .'</base64>';
341341
}
342342

343-
/**
344-
* Perform an XML-RPC request.
345-
*
346-
* @param $url
347-
* An absolute URL of the XML-RPC server
348-
* @param $method
349-
* The method to be executed
350-
* @param ...
351-
* A variable number of arguments of the method.
352-
* @return
353-
* The return value of the method on success or FALSE. On FALSE, see
354-
* xmlrpc_errno() and xmlrpc_error_msg().
355-
*/
356-
function xmlrpc() {
343+
function _xmlrpc() {
357344
$args = func_get_args();
358345
$url = array_shift($args);
359-
$method = array_shift($args);
346+
if (is_array($args[0])) {
347+
$method = 'system.multicall';
348+
$multicall_args = array();
349+
foreach ($args[0] as $call) {
350+
$multicall_args[] = array('methodName' => array_shift($call),'params' => $call);
351+
}
352+
$args = array($multicall_args);
353+
}
354+
else {
355+
$method = array_shift($args);
356+
}
360357
$xmlrpc_request = xmlrpc_request($method, $args);
361-
// $request .= "Content-Type: text/xml$r";
362358
$result = drupal_http_request($url, array("Content-Type" => "text/xml"), 'POST', $xmlrpc_request->xml);
363359
if ($result->code != 200) {
364360
xmlrpc_error(-$result->code, $result->error);
@@ -380,30 +376,6 @@ function xmlrpc() {
380376
return $message->params[0];
381377
}
382378

383-
/**
384-
* Perform multiple calls in one request if possible.
385-
*
386-
* @param $url
387-
* An absolute URL of the XML-RPC server
388-
* @param $calls
389-
* An array of calls. Each call is an array, where the first element
390-
* is the method name, further elements are the arguments.
391-
* @return
392-
* An array of results.
393-
*/
394-
function xmlrpc_multicall() {
395-
$args = func_get_args();
396-
$url = $args[0];
397-
foreach ($args[1] as $call) {
398-
$method = array_shift($call);
399-
$calls[] = array(
400-
'methodName' => $method,
401-
'params' => $call
402-
);
403-
}
404-
return xmlrpc($url, 'system.multicall', $calls);
405-
}
406-
407379
/**
408380
* Returns the last XML-RPC client error number
409381
*/

‎xmlrpc.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* PHP page for handling incoming XML-RPC requests from clients.
77
*/
88

9-
include_once 'includes/bootstrap.inc';
9+
include_once './includes/bootstrap.inc';
1010
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
11-
include_once 'includes/xmlrpcs.inc';
11+
include_once './includes/xmlrpc.inc';
12+
include_once './includes/xmlrpcs.inc';
1213

1314
xmlrpc_server(module_invoke_all('xmlrpc'));
1415
?>

0 commit comments

Comments
 (0)