PHP and Web Services – essential reading

An old web service implemented in PHP have been giving me some headache the last couple of days. Especially interoperability with clients implemented in other languages (like .NET) are troublesome. It seems to me that PHP is very forgiving. Which is good – sometimes – but not always. PHP let you get away with a lot when creating your web services. So just because your PHP client play along nicely doesn’t mean other clients will work. Far from it.

So after loads of googling I came to realise that even though 2010 is just around the corner there are still very few quality articles on PHP and web services/SOAP available. Most of the stuff I find is rubbish where people who don’t know nothing explain things they don’t understand.

So even though these articles below are old, they will give most people a very good grasp on how, and why, to create a SOAP web service using PHP that will work. (And a very short advice; use document/literal style for better interoperability with for example .NET and don’t use preserved words like “ref” as parameter (message parts) names for better interoperability with for example .NET).

  1. Which style of WSDL should I use?
  2. PHP SOAP Extension

A comment about the second article is in place though. I generally tend to favour mapping WSDL defined operations to methods in a class. So instead of using PHP methods like $server->addFunction(), use $server->setClass(). More on setClass() in the manual.

Tagged with: , ,
Posted in PHP
5 comments on “PHP and Web Services – essential reading
  1. A good reading about PHP & SOAP interoperability I found was: Why does SOAP leave me feeling so dirty?

    The thing is PHP SOAP extension does not support document/literal wrapped style well – and this bould bite you sometimes as it’s the preferred convention right now as I understand it. See also PHP bug 30302

  2. Ivo Krastev says:

    Basically you can use php SOAP extension for rpc/encoded and nuSOAP for document/literal. This my “perfect” combination and it works for 3 years now at our company.

  3. Pete says:

    Ivo,

    If you can install it, good luck – I tried yesterday on Win and Mac and failed miserably. I don’t have loads of time to fix it so I’m still looking for a more appropriate solution.

    Not interested in SOAP – I’m after a RESTful solution.

    Cheers

    Pete…

  4. Danne says:

    I have never actually tried any of the other solutions. SOAP should, in my opinion, be supported natively. The more people using it the more pressure on keeping it up to date…

    Krzysztof: See my comments on bug 30302 at PHP, SOAP and operation signatures

    Pete: RESTful calls don’t need any fancy protocol other than http. That’s the beauty of it. (As long as you design API well that is). JSON format is almost standard in sending data back and forth and makes it easy to use such an API with many languages.

1 Pings/Trackbacks for "PHP and Web Services – essential reading"
  1. [...] Lundqvist has a quick new post with pointers to two articles that’re good resources for getting you started with web [...]

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>