WSDL caching in NuSOAP

If you are using NuSOAP to make SOAP calls from PHP, make sure you're caching your WSDL files using the wsdlcache class.

Without caching NuSOAP downloads and parses the WSDL file each time you construct a new nusoap_client object:

require_once('/lib/nusoap.php');

$url = 'http://example.com/test.wsdl';
$client = new nusoap_client($url, 'wsdl', '', '', '', '');

The code with caching looks like this:

require_once('lib/nusoap.php');
require_once('lib/class.wsdlcache.php');

$url = 'http://example.com/test.wsdl';
$cache = new nusoap_wsdlcache('/tmp', 86400);
$wsdl = $cache->get($url);
if(is_null($wsdl))
{
  $wsdl = new wsdl($url, '', '', '', '', 5);
  $cache->put($wsdl);
}
$client = new nusoap_client($wsdl,'wsdl','','','','');

There is nice sample program included in the documentation.

In a recent project, caching the fairly large WSDL file saved two (2) seconds.

Topic: 

15 Comments

Hi Thanks for this

Hi

Thanks for this information. I have a NuSoap web service working 100% ok but have a question...

If I don't specicy my NuSOAP web service is using a WDSL does some caching take place anyways?

My current web service gives the following reposnse when viewed in a browser...

method & apos not defined in service
"

Hi, Thanks for this clear

Hi,
Thanks for this clear example.
But if your SOAP server is behind a HTTP authentication, there is a tiny trick to be able to cache your wsdl file :


if(is_null($wsdl))
{
// Here is the trick : you must leave the WSDL URI empty when instanciating your wsdl object. Otherwise he will try to fetch and result in an HTTP authentication error.
$wsdl = new wsdl('', '', '', '', '', 5);

// set up HTTP auth login/pwd
$wsdl->setCredentials($username,$password);

// Now we can fetch the wsdl data.
$wsdl->fetchWSDL($url);

$cache->put($wsdl);
}

I am pretty new to web

I am pretty new to web services but...

If you use a class and instantiate the new soap client in the constructor and create methods for all your soap requests would the wsdl be held in the class object and only fetched once?

example:

__construct(){
$this->soap_client = new nusoap_client($url,'wsdl','','','','');
...
}

public function CreateNewEntry(){
$this->soap_client->call('soapcall',$params);
....
}

Not sure if this makes sense but each soap call does not fetch the wsdl file correct?