2024 年 PHP Conference Japan

xmlrpc_server_call_method

(PHP 4 >= 4.1.0, PHP 5, PHP 7)

xmlrpc_server_call_method解析 XML 請求並呼叫方法

說明

xmlrpc_server_call_method(
    資源 $server,
    字串 $xml,
    混合型別 (mixed) $user_data,
    陣列 (array) $output_options = ?
): 字串 (string)
警告

此函式為*實驗性*。此函式的行為、名稱和周圍的文件可能會在未來的 PHP 版本中更改,恕不另行通知。使用此函式需自行承擔風險。

警告

此函式目前沒有說明文件;僅提供其參數列表。

新增註記

使用者貢獻的註記 2 則註記

5
marco.buratto at tiscali punto it
17 年前
xmlrpc_server_call_method() 與類別方法

<?php
require_once ('Connections/adodb_mysql_connection.php');

// Instantiating my own class
$my_report = new external_report($db_connection);

// Setting up the XML-RPC "server"
$xmlrpc_server_handler = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server_handler, "external_method", array(&$my_report, "export"));

// Creating XML return data
if ($response = xmlrpc_server_call_method($xmlrpc_server_handler, $HTTP_RAW_POST_DATA, null))
{
header('Content-Type: text/xml');
echo
$response;
}

// **************** class definition ****************

class external_report
{
protected
$db_connection;

public function
__construct($db_connection_pointer)
{
if (
method_exists($db_connection_pointer, "Execute")) $this->db_connection = $db_connection_pointer;
else die(
"...");
}

public function
export($method_name, $params_array)
{
$id_dir = (int)$params_array[0];
$id_usr = (int)$params_array[1]; // not used, just an example
// We have to add arguments' validating code here and NOT inside the constructor (as usual)
// because arguments are passed directly by xmlrpc_server_call_method (?!!)

$myexport = array();

$dirs_query = "SELECT documento_id FROM tabella_cartelle WHERE cartella_id = ".$id_dir;
$dirs_result = $this->db_connection->Execute($dirs_query) or die("...");

$index = 0;
while(!
$dirs_result->EOF)
{
$docs_query = "SELECT codice, titolo FROM tabella_documenti WHERE id_documento = ".$dirs_result->Fields('documento_id');
$docs_result = $this->db_connection->Execute($docs_query) or die("...");

$myexport[$index]['codice'] = $docs_result->Fields('codice');
$myexport[$index]['titolo'] = $docs_result->Fields('titolo');

$index++;
$dirs_result->MoveNext();
}

return
$myexport;
}
}
?>
-2
nyvsld at gmail dot com
19 年前
<?php
/* 方法實作 */
function impl($method_name,$params,$user_data){
var_dump(func_get_args('impl'));
return
array_sum($params);
}

/* 建立伺服器 */
$s=xmlrpc_server_create();
xmlrpc_server_register_method($s,'add','impl');

/* 呼叫伺服器方法 */
$req=xmlrpc_encode_request('add',array(1,2,3));
$resp=xmlrpc_server_call_method($s,$req,array(3,4));

/* 處理結果 */
$decoded=xmlrpc_decode($resp);
if(
xmlrpc_is_fault($decoded)){
echo
'fault!';
}

var_dump($decoded);
?>
To Top