php function call_socket remote_server remote_server_port remote_path

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
function call_socket($remote_server, $remote_server_port,$remote_path, $request) {
$sock = fsockopen($remote_server, $remote_server_port, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)\n");
$out = "POST $remote_path HTTP/1.1\r\n";
$out .= "User-Agent: PHPRPC/1.0\r\n";
$out .= "Host: $remote_server\r\n";
$out .= "Content-type: text/xml\r\n";
$out .= "Content-length: " . strlen($request) . "\r\n";
$out .= "Accept: */*\r\n\r\n";
$out .= "$request\r\n\r\n";
fputs($sock, $out);
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n"; $data = "";
while (!feof($sock))
$data .= fgets($sock, 4096);
fclose($sock);
return $data;
}
function make_request($request_xml, &$output) {
$retval = call_socket('mysite.local', 80, '/xml-rpc/xml-rpc-server.php', $request_xml);
$data = xmlrpc_decode($retval);
if (is_array($data) && xmlrpc_is_fault($data)){
$output = $data;
}else{
$output = unserialize(base64_decode($data));
}
}
?>