Yeah, that seems to work.  Here is what I changed my client/server to:

CLIENT:
<?php
require_once 'XML/RPC.php';

$client = new XML_RPC_Client('/xmlrpc.php', 'localhost');
$msg = new XML_RPC_Message('stuff');
$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());
}
?>


SERVER: <?php require_once 'XML/RPC/Server.php';

function foo()
{
$uptime = `uptime`;
return new XML_RPC_Response(new XML_RPC_Value("return string!", 'string'));
}


$dispatches = array('stuff' => array('function' => 'foo'));
new XML_RPC_Server($dispatches, 1);
?>


Thanks tons!! --Jough

On Aug 6, 2004, at 3:02 PM, Justin Philpott wrote:

Hi Jough,

After getting spooked that you'd managed to find another manifestation
of a bug that I'd thought I'd fixed the other day I was releaved to find
that was not the case - however you have uncovered an interesting
drawback of the PEAR XML RPC lib, in that it doesn't like the use of
"system." at the start of the method name.


I've done some testing and I think I've narrowed it down to that
combination at the start of the methodName. The approx. reason for this
is that the methodName goes through an eval() function which is
confusing PHP when it finds "system." without the quotes.

Hmmmm... XML RPC really needs to have a more flexible and robust way of
specifying which function to call. Using eval() as an integral part of
that only leads to problems in the end. It should not be necessary.

If I had time I'd rewrite that part of the RPC lib. and I may just do
that!

See code following which is essentially yours, play around with
having/not having "system." at the start of the methodName and you'll
see it works without! Perhaps you may find some other combinations which
the lib doesn't like! :-/


===================================================
// SERVER
<?php
require_once 'XML/RPC/Server.php';
function system_load()
{
        // stuff...
    {
       return new XML_RPC_Response(new XML_RPC_Value("return string"));
    }
}
$dispatches = array('system.Load' => array('function' =>
'system_load'));

$server = new XML_RPC_Server($dispatches, 1);
?>

// CLIENT
<?php
require_once 'XML/RPC.php';

$client = new XML_RPC_Client('/server_test.php', 'Kali', 80);
$client->setDebug(1); // helps!
$msg = new XML_RPC_Message('system.Load', array(new XML_RPC_Value("test
string")));
$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());
}

?>

=======================================================

Hope this helps,

Justin


-----Original Message----- From: Jough P [mailto:[EMAIL PROTECTED] Sent: 06 August 2004 19:31 To: PHP; Justin Philpott Subject: Re: [PEAR] PHP5 and XML-RPC


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:[EMAIL PROTECTED]
Sent: 31 July 2004 19:00
To: [EMAIL PROTECTED]
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


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to