How to implement on localhost xml_rpc client in PHP?

900 views Asked by At

Hello i have somme problems to write a simple XML-RPC client in PHP. This is my PHP code:

$site_name  = "Mikangali";
$site_url   = "http://www.mikangali.com";
$site_url   = "http://localhost";

$request = xmlrpc_encode_request("weblogUpdates.ping", array($site_name, $site_url));

#echo $request;

$http_request = array(
    'method'    => "POST",
    'header'    => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\nHost: rpc.technorati.com\r\n",
    'content'   => $request
);

#print_r($http_request) ;

$context = stream_context_create(array('http' => $http_request));

$file = @file_get_contents($server_url, false, $context);

 if ($file==false) { 

    #handle error here... 
    display_mssg("error","! we get a pb !");
 }

$response = xmlrpc_decode($file);

if (is_array($response) and xmlrpc_is_fault($response)){
    display_mssg("error","Failed to ping ".$site_name);
} 
else {
    display_mssg("success","Successfully pinged ".$site_name); 
    var_dump($response);
    var_dump($file);
}

I can't figure out why it enter on the "success" condition and display me that:

! we get a pb !

Successfully pinged Technorati
null
boolean false

Thanks for you help. Notice that XML-RPC PHP extention is activated, on my local wamp server.

1

There are 1 answers

0
DieVarDump On BEST ANSWER

Surely because xmlrpc_decode(false) is returning null $file = false, cause you have a problem. ( => ! we get a pb ! )

So you don't get into the if which is checking that $response is an array.