The January 2005 meeting of the SDForum Web Services SIG featured a presentation on “PHP5 & Web Services” by Andi Gutmans (a co-founder of Zend). Following are my notes and comments from the presentation.
PHP5 released in July 2004. PHP highlights; what are the key reasons it’s so popular?
- Rapid, iterative development cycles, low learning curve
- Robust, high-performance & scalable; stable & secure
- Easily integrated into heterogeneous environments/systems
- Proven through widespread deployment; vibrant community
TIOBE Programming Community Index (January 2005); PHP earned the title of “Programming Language of the Year 2004“.
- Allows for real object orientd development (but doesn’t force OO; can still use as functional language)
- Integration capabilities (Web Services, C/C++, Java, Perl, .NET, etc.)
- Databases (Oracle, DB2, MySQL, MS SQL, etc.)
- Support for standards (XML, LDAP, SNMP, etc.)
Web Services — why another SOAP implementation?
- PHP4 had no standard SOAP implementation
- Several non-standard implementations (NuSOAP, PEAR::SOAP)
- Needed a standard, bundled, high-performance, reliable implementation
- For PHP5, Zend wrote an entirely new implementation, bundled by default (need to recompile PHP to activate)
Consuming Web Services
- Use SoapClient class
- Two modes
* Easy way: WSDL file import (easy unless you have to write the WSDL)
* Harder: programmatically describe the web service
Exposing Web Services
- Use SoapServer class
- Two modes
* WSDL file
- SoapServer can receive and optional array of arguments like SoapClient
- One problem now: no good way to generate WSDL from PHP itself
PHP’s XML Magic (SimpleXML)
- Treat XML values as native PHP types
- Takes advantage of new Zend engine overloading API
- Takes advantage of the dynamic nature of PHP
- Based on libxml2 library
Examples show function simplexml_load_file() which in a single step creates a PHP XML object from either a file or a live URL. You can then iterate through the item using dynamic element/attribute names.
SOAP in PHP4?
- Yes, compatible with PHP4
- Not distributed by default; download and build it separately
- Works very much the same way (no exceptions, for example)
- Sending cookies in SOAP envelope (5.0.4)
- HTTP digest authentication (5.0.4)
- SOAP attachments (MIME, DIME)
- SOAP routing and WS-Security
- Method overloading
- Better development tools (WSDL creation, web services explorer, code templates, code completion)
New projects tend to be starting in PHP5, but conversion from PHP4 will likely take time. Apparently making the upgrade isn’t too difficult, but organizations are taking it cautiously.