Zeev Suraski - PHP Conference day 2

Tuesday May 3 2005

ForumAs promised, today I'll be blogging live from the PHP Conference. Right now I'm listening to Zeev Suraski on a presentation on PHP as an integration platform. He states that PHP5 is the first version of PHP that allows for real Object Oriented development. Some of it's integration capabilities relate to Web Services, C/C++, Java and Perl and COM/.NET. Of course all major databases are supported including the commercial ones. Supports for standards is extremely extensive and includes XML, LDAP, SNMP, IMAP and much more.

Dark Matter Pro: a premium photoblog template.

Affiliate program available

Consuming Web Services



Web Services can be used with the SoapClient class which has two modes of operation:
  • WSDL based
  • programmatically describing the Web Service using the ext/soap API


The Soap extension comes with PHP5 but isn't enabled by default. You'll have to do this before you can use it.

It's ridiculously simple to use:


if isset($_GET["spellString"]) {
$spellString = $_GET["spellString"];

// instantiate Soap object with the WSDL file as an argument. This file
should be downloaded and stored locally.

$google = new SoapClient("googleapi/GoogleSearch.wsdl");

$result = $google->doSpellingSuggestions(" --- google API key here ---", $spellString);
if($result) {
echo "The result of your request $spellString was: $result";
}
else {
echo "Google didn't return any suggestion.";
}
}


Pretty nifty indeed! All complexity and XML issues are completely hidden from the user. Of course this is just a simple example that I could manage to quickly get from the presentation. The second example that was presented shows how you can send search requests to Google using it's webservice and use the result in your own application. Even though it's a bit more code (too much to type for now) it's extremely simple just like the above example.

Deploying a Web Service




class Fortune {
function getFortune() {
return '/usr/games/fortune';
}
function getExtendedFortune() {
return array("timeStamp" => time(), fortuneText => '/usr/games/fortune');
}
}

$SOAP = new SoapServer("Fortune.wsdl");
$SOAP->setClass("Fortune");
$SOAP->handle();


Voila. We've got our own fortunes web service!

The WSDL file


The WSDL file is an XML document describing the web service. Using one with the Soap client is simple but writing one is somewhat more complex. At this point unfortunately there aren't any tools yet that can generate it for you which is why this is a bit harder. The best way to do it today is to take an existing WSDL file and modify it to fit your own web service. It's not too hard if you concentrate for a while.

The fun doesn't stop here. We can even add persistence to our Web Service by using:


$SOAP->setPersistence(SOAP_PERSISTENCE_SESSION);


If we receive multiple occurrences of the same request from the same client, persistence can occur. Therefore we can set whatever members on (in this example) our Fortune object and they'll persist between requests if they are sent from the same piece of code, for example a for-loop sending multiple requests in a piece of code using the Soap client.

After this interesting introduction on Soap Zeev continues on SimpleXML. I'll finish this first post here in order to save some battery capacity. I plan to write on SimpleXML myself in the future anyway. Stay tuned for more today.
bookmarking

Commentary

Join the discussion! Leave a comment through the comment form below!

Got something to add to this?

Feel free to leave a comment on this site. You can use Textile and Emoticons. Your email address is only used to show a gravatar. Please stay on-topic and use common decency. Spammers will be shot in front of a live studio audience.

If you plan on posting code, use pastebin please and post a URL to the code. The comment processing doesn't deal very well with code. Sorry for the inconvenience.

Human comment spammers: don't bother posting your crap here. Comments are moderated and I won't let any of your shit through.

Remember personal info?
Yes
No

Trackbacks

If you have an interesting related post on your own site you can leave a trackback. As they say: 'a little AJAX a day keeps the spammers away' which is why you'll have to click below to generate a trackback key. The key will be valid for 15 minutes and can be used only once.

 

  • Featured Links
RockySomewhere near the Orion NebulaBookalicio.usGolden Gate BridgeThames River BankJackie and mePimpin' it