Re: PHP5 and XML-RPC

From: Date: Fri, 06 Aug 2004 18:30:58 +0000
Subject: Re: PHP5 and XML-RPC
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-193027@lists.php.net to get a copy of this message
Hi There! Thanks for your reply! Sorry it's taken awhile to respond. Anyhow, I changed my code to the following: require_once 'XML/RPC.php'; $client = new XML_RPC_Client('/xmlrpc.php', 'localhost'); $msg = new XML_RPC_Message('system.load'); $result = $client->send($msg); if($result->faultCode()) { // we have an error echo "Error Code: " . $result->faultCode() . "<BR>"; echo "Error String: " . $result->faultString() . "<BR>"; } else { // no error, you should get some decoded value out print XML_RPC_decode($result->value()); } print XML_RPC_decode($result->value()); And I get the following: Error Code: 1 Error String: Unknown method Fatal error: Call to a member function kindOf() on a non-object in /usr/local/php5/lib/php/XML/RPC.php on line 1083 It seems to say that $client does not have a send method. Surely this isn't the case? Thanks! All help is appreciated!! I'll be much quicker to respond this time! --Jough On Aug 2, 2004, at 12:03 PM, Justin Philpott wrote:
Hi Jough, By looking at line 1083 I can see that whatever is getting passed to XML_RPC_decode() is not a valid XML_RPC_Value object By looking at the code, if a fault were to occur, it still tries to printout the value of the result. Reading the PEAR XML_RPC API docs says this: "If the response's faultCode is non-zero then the value returned by this method should not be used (it may not even be an object)" ... I think this may be the problem, so get it to print the faultCode and faultString but like this instead: if($result->faultCode()) { // we have an error
    	echo "Error\n"; // print the code and string here
} else { // no error, you should get some decoded value out print XML_RPC_decode($result->value()); } // always use {} with control structures, if you don't it will bite you in the ass eventually... // and remember to turn on debugging to see what's going on... hope this helps, Justin -----Original Message----- From: Jough P [mailto:jough@wiretapped.us] Sent: 31 July 2004 19:00 To: pear-general@lists.php.net Subject: [PEAR] PHP5 and XML-RPC Greetings all, I'm copying code straight out of _Advanced PHP Programming_ and am getting the following error on a Linux/Apache/PHP5 box: Fatal error: Call to a member function kindOf() on a non-object in /usr/local/lib/php/XML/RPC.php on line 1083 I'm wondering if the pear XML-RPC class has any issues with PHP 5. But, I'm just learning how to use XML-RPC and could very well be doing something stupid. ANY help at all would be greatly appreciated. Here is the code: CLIENT: <?php require_once 'XML/RPC.php'; $client = new XML_RPC_Client('/xmlrpc.php', 'localhost'); $msg = new XML_RPC_Message('system.load'); $result = $client->send($msg); if($result->faultCode())
    echo "Error\n";
print XML_RPC_decode($result->value()); ?> SERVER: <?php require_once 'XML/RPC/Server.php'; function system_load() {
    $uptime = uptime;
    if(preg_match("/load average: ([\d.]+/", $uptime, $matches))
    {
       return new XML_RPC_Response(new XML_RPC_Value($matches[1],
'string'));
    }
} $dispatches = array('system.load' => array('function' => 'system_uptime')); new XML_RPC_Server($dispatches, 1); ?> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#193027) next »