Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP > PHP Application Design
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Sep 2, 2002, 07:59   #1
Skunk
Grumpy Mole Man
 
Skunk's Avatar
 
Join Date: Jan 2001
Location: Lawrence, Kansas
Posts: 2,190
A new XML-RPC library for PHP

Hi all,

I've released the first version of my XML-RPC library for PHP. There are plenty of others out there but none of them really worked for me (they were either too complicated or didn't work well with PHP 4) so I wrote my own. It's designed to make XML-RPC queries and implementing a full XML-RPC servers as easy as possible - the code handles all type conversions between PHP and XML-RPC transparently meaning XML-RPC calls and responses are almost as simple as makign native PHP function calls.

You can check out the library here: http://scripts.incutio.com/xmlrpc/

It's pseudo-OOP (it uses classes but they aren't particularly well abstracted) but as XML-RPC is a concrete standard I saw no reason to make the code any more modular than it had to be. I'm pretty pleased with it so far - it needs a bit more work (<date> support and better error handling mainly) but it's ready for use now - in fact I'm already using it as part of my new PingBack system.

Feedback and suggestions welcome - here, or through the contact form on my blog

Thanks,

Simon
Skunk is offline   Reply With Quote
Old Sep 2, 2002, 10:04   #2
HarryF
SitePoint Wizard
gold trophysilver trophy
 
Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
That's looking good. Nice use of variable reflection. If I can dare to make one suggestion: would be good to seperate the HTTP client as a seperate object from the XML-RPC client.

There's a good HTTP client class here: http://www.phpclasses.org/browse.html/package/3.html

The client still needs one or two things, namely SSL connections (using Curl perhaps or with PHP 4.3 fsockopen can access SSL sites if OpenSSL is compiled with PHP) and HTTP Basic Authentication.

Also on the server side, would be great if there was a mechanism build in HTTP Authentication headers (again as a seperate class) - there's an Authentication class here: http://sourceforge.net/projects/httpauthplus/

The reason is there's not a single XML-RPC class yet that handles HTTP fully. There's hardly even a complete PHP HTTP client to work with either.

May be the ISO8601 types can be spotted in the strtotime() function?

Also system.multicall would be good, as an in built mechansim (http://www.xmlrpc.com/discuss/msgReader$1208) and a means to build in introspection automatically.

Sorry man You asked. Reckon if you can do it all, you'll have the #1 XML-RPC library. Anyway great start!
HarryF is offline   Reply With Quote
Old Sep 2, 2002, 11:40   #3
Skunk
Grumpy Mole Man
 
Skunk's Avatar
 
Join Date: Jan 2001
Location: Lawrence, Kansas
Posts: 2,190
Wow, that's exactly the kind of feedback I was after. Thanks

/me starts reading
Skunk is offline   Reply With Quote
Old Sep 2, 2002, 11:52   #4
Skunk
Grumpy Mole Man
 
Skunk's Avatar
 
Join Date: Jan 2001
Location: Lawrence, Kansas
Posts: 2,190
I can't find the specification for the suggested XML-RPC introspection methods anywhere. Any ideas?
Skunk is offline   Reply With Quote
Old Sep 2, 2002, 14:41   #5
HarryF
SitePoint Wizard
gold trophysilver trophy
 
Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
Seems Useful seem to be slowly "losing" their documentation (could be cause they want SOAP to take off). The introspection stuff should be here: http://xmlrpc.usefulinc.com/doc/reserved.html

But anyway, this is what I have form the Useful library documentation (comes with their classes);

Quote:
In order to extend the functionality offered by XML-RPC servers without impacting on the protocol, I've included experimental support in this release for reserved methods.

All methods starting with system. are considered reserved by the server. PHP for XML-RPC itself provides three special methods, detailed in this chapter.

system.listMethods
This method may be used to enumerate the methods implemented by the XML-RPC server.

The system.listMethods method requires no parameters. It returns an array of strings, each of which is the name of a method implemented by the server.

system.methodSignature
This method takes one parameter, the name of a method implemented by the XML-RPC server.

It returns an array of possible signatures for this method. A signature is an array of types. The first of these types is the return type of the method, the rest are parameters.

Multiple signatures (ie. overloading) are permitted: this is the reason that an array of signatures are returned by this method.

Signatures themselves are restricted to the top level parameters expected by a method. For instance if a method expects one array of structs as a parameter, and it returns a string, its signature is simply "string, array". If it expects three integers, its signature is "string, int, int, int".

If no signature is defined for the method, a none-array value is returned. Therefore this is the way to test for a non-signature, if $resp below is the response object from a method call to system.methodSignature:

PHP Code:

$v=$resp->value();

if (
$v->kindOf()!="array") {
  
// then the method did not have a signature defined
}
system.methodHelp
This method takes one parameter, the name of a method implemented by the XML-RPC server.

It returns a documentation string describing the use of that method. If no such string is available, an empty string is returned.

The documentation string may contain HTML markup.
Using the O'Reilly Meerkat, there's an example of system.listmethods: http://meerkat.oreillynet.com/xml-rp...em.listMethods

Will see if can come up with some more info later.
HarryF is offline   Reply With Quote
Old Sep 2, 2002, 15:46   #6
Skunk
Grumpy Mole Man
 
Skunk's Avatar
 
Join Date: Jan 2001
Location: Lawrence, Kansas
Posts: 2,190
Thanks - I eventually found their documentation in the Google cache

I've taken the liberty of quoting your comments almost in their entirity on my blog, as it turns out people who aren't logged in to the forums can't view threads on the Advanced PHP forum (doh!). Hope you don't mind:

http://www.bath.ac.uk/~cs1spw/blog/a...9/02/#feedback

Cheers,

Simon
Skunk is offline   Reply With Quote
Old Sep 15, 2002, 12:57   #7
Michel V
will code HTML for food
 
Michel V's Avatar
 
Join Date: Sep 2000
Location: Corsica
Posts: 552
Now all we need is that you code the same for SOAP someday
(it would be just great to have that kind of library work with both SOAP and XMLRPC with just a switch between protocols needed, as it would dramatically reduce web-services development time)
__________________
[blogger: zengun] [blogware contributor: wordpress]
Michel V is offline   Reply With Quote
Old Sep 15, 2002, 14:17   #8
HarryF
SitePoint Wizard
gold trophysilver trophy
 
Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
That does exist. It's the native XML-RPC PHP extension - it's capable of receiving and sending SOAP 1.1 messages. If it gets a SOAP message, it tries to convert it to PHP variables (works most of the time). It's pretty well hidden (like here) but basically here's an example;

PHP Code:

$output = array ("version" => "soap 1.1");

$params = array ("system.listMethods");
$request = xmlrpc_encode_request("system.methodHelp", $params, $output);
echo (
$output);
Produces;

Code:
<?xml version='1.0' encoding="iso-8859-1" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd" xmlns:ns6="http://testuri.org" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
 <system.methodHelp>
  <xsd:string>system.listMethods</xsd:string>
 </system.methodHelp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Compare that with the XML-RPC version;

PHP Code:

$output = array ("version" => "xmlrpc");

$params = array ("system.listMethods");
$request = xmlrpc_encode_request("system.methodHelp", $params, $output);
echo (
$output);
Produces;

Code:
<?xml version='1.0' encoding="iso-8859-1" ?>
<methodCall>
<methodName>system.methodHelp</methodName>
<params>
 <param>
  <value>
   <string>system.listMethods</string>
  </value>
 </param>
</params>
</methodCall>
Course that requires the XML-RPC extension be installed with PHP. In my opinion Skunks library is on it's way to being the best XML-RPC implementation which requires no installed extensions. And some things it does alot better than the native extension (like allowing you to easily build OO code on top of his library). Skunk definately has the know how to extend his classes for SOAP, looking at his Amazon class (time to do it though is no doubt another matter ).

The other general option for transforming XML-RPC to SOAP is with XSLT - for a starter, try this: http://www.xmlrpc.com/discuss/msgReader$559. Course XSLT requires the Sablotron extension to PHP (haven't found any XSL parser written in PHP)
HarryF is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

 
Forum Jump


All times are GMT -7. The time now is 21:09.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved