一个倒霉的routine问题,请求高人解答
这个作业的要求是写一个php routine , 其参数应为一组服务器的名字和一个http
request的string.
routine的返回值应为各个服务器对于respones of http request的汇总. 其中的HTTP
request包含的信息为xml-rpc.
大概是这个样子
function send_http($nodes,$request) {
// Arguments: array of node addresses, XMLRPC request.
$output=array();
foreach($nodes as $i = > $node) {
// Open SSH tunnel
...
// Send command to node over HTTP, get results
...
// Store results
$output[$node]=$result;
// Close SSH tunnel
...
return($output);
}
-----------------------------------------------------------
对于$nodes, 暂时不太知道怎么获取, 可能有人会写那种返回值就是array of node adressed的函数, 到时候调用一下.
这个我再问问他们,是调用别人的,还是需要自己写.
对于"// Open SSH tunnel", 感觉可以用ssh2的 ssh2_tunnel.
对于"// Send command to node over HTTP, get results",
感觉可以用这个函数的办法,或者调用.(因为这个函数是别人写的,所以不知道在调用上会不会出现问题)
function remote_call($function_name, $params)
{
$request_xml = xmlrpc_encode_request($function_name, $params);
$context = stream_context_create(
array('http' = > array(
'method' = > "POST",
'header' = > "Content-Type: text/xml",
'content' = > $request_xml
)));
$response_xml = file_get_contents($this- >rpc_server_url, false, $context);
$response = xmlrpc_decode($response_xml);
if (xmlrpc_is_fault($response))
{
$this- >last_fault = $response;
$response = NULL;
}