Home arrow PHP arrow Page 3 - Developing SOAP Clients using PHP


SOAP (Simple Object Access Protocol) provides a flexible communication layer between applications, regardless of platform and location. As long as both the server and the client speak SOAP, they can communicate. A PHP-based web application can ask a Java database application to get some information. In this article we will try to focus on different methods of developing SOAP web service clients in PHP.

  1. Developing SOAP Clients using PHP
  2. Debugging NuSOAP
  4. PHP's SOAP Extension
By: Mamun Zaman
Rating: starstarstarstarstar / 10
August 14, 2007

print this article



Let us assume that our web service is described at http://localhost/add.wsdl. To create a PEAR::SOAP client you can use the example below.

require_once 'SOAP/Client.php';

$url = 'http://localhost/add.wsdl';
$WSDL = new SOAP_WSDL($url);
$client = $WSDL->getProxy();

$params = array(
    'a' => 1,
    'b' => 6

$result = $client->add($params);


The first line includes PEAR::SOAP's client classes. If you have trouble loading the files, make sure your include_path contains the folder where PEAR files are stored. You first instantiate a new SOAP_WSDL object by passing $url, the location of our web service's WSDL file, to the constructor. Next, SOAP_WSDL::getProxy() is called, and it returns a client object, $client. This is what you use to make SOAP requests. Now make the actual add() query. This method takes a few arguments, which are passed in as an (associative) array. Parameter names are the array's keys, and their values are array values.

PEAR:SOAP converts your PHP data structures to a SOAP message written in XML and sends an HTTP request to the web server. PEAR::SOAP listens for the server's response and parses the XML into a PHP object, which is then returned by our method and stored in $result. Then we print the result value.

Installing PEAR::SOAP is very easy if you have a pear manager installed in your server. Use the following shell command for installing PEAR::SOAP.

pear install SOAP

This will download, unzip, and install PEAR::SOAP. Depending on which packages you've yet to install, you may get a dependency error. First install the dependent packages and then install SOAP.

>>> More PHP Articles          >>> More By Mamun Zaman

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: