OSCON: Web Services in PHP

Web Services in PHP, Adam Trachtenberg (Slides will be at this URL later today)

Have you used Web Services? What is a Web Service?

Adam: Normally, I would say what company I’m working for, but since I’m unemployed, I can’t. (Audience laughs nervously).

1:45 PM: A Web Service is a network accessible interface to application functionality built using XML and usually HTTP. Tim O’Reilly this morning mentioned companies like Amazon and Google that are using Web Services.

1:50 :Where’s my FedEx package? Sort of a manual procedure. Going to FedEx.com – It’s a manual process. Amazon can automate this and includes this data on a per-user basis, and this makes it nice. Stock data is another example.

1:52 PM: Why do we care? These interfaces work regardless of the client’s and server’s platform and language. It is platform-neutral.

1:54 PM: Three forms of Web Services: SOAP, XML-RPC and REST.

1:55 PM: This talk covers: SOAP client, SOAP server, XML-RPC, REST client and querying Amazon.com.

1:56 PM: the dirty little secret about Web Services is that there’s a lot of type, but very few companies that actually have APIs that you can use. There’s basically Amazon and Google, and Amazon…and Google. And Amazon…

1:57 PM: SOAP: Uses XMl, but you never need to touch it. You just call functions and manipulate arrays. A few PHP implementations: PEAR::SOAP, PHP-SOAP, NuSOAP.

1:58 PM: Dirty little secret: Nobody uses SOAP.

1:59 PM: A lot of people like NuSOAP. PEAR::SOAP is easy to install.

2:00 PM: First you build your request. 1. Load the SOAP client. 2. Generate the client proxy. WSDL is a machine-readable description (XML) of a web service, used here to define server’s methods and parameters.

2:02 PM: Technical discussion. Refer to slides.

2:06 PM: What we get after processing: SOAP-based data, yuck. What we see: a nice simple PHP object; much better.

2:08 PM: Now, how do I parse it? Just do a simple foreach loop.

2:09 PM: Boom: nice HTML output. Nice WSDL object is about 7 lines of code.

2:10 PM: $server->addObjectMap($soapclass , ‘urn:SOAP-Server_rot13’);

2:16 PM: That was a basic two-slide SOAP example (refer to slides for code).

2:17 PM: Moving on to XML-RPC.

2:18 PM: Similar to SOAP but less complex, which is its biggest advantage and also its biggest disadvantage. Written by Dave Winer.

2:19 PM: SOAP has better buzzword-compliance than XML-RPC.

2:20 PM: REST: Representational State Transfer (Roy Fielding)

2:21 PM: Data is returned as XML, and you do need to touch it, which is good because it is not complicated.

2:22 PM: Many ways to parse XML: SAX/DOM/XSLT

2:23 PM: See slides for REST example of Construct Query String

2:24 PM: Use cURL to make get request. Or use any query utility.

2:25 PM: XML Results: like SOAP, but cleaner. Create SAX parser, Instantiate Object, Configure Parser….(see slides)

Posted by Cameron Barrett at July 9, 2003 04:46 PM

Leave a Reply

Your email address will not be published. Required fields are marked *