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.

15 Comments
*gasp*! Since when do "web
Submitted by Philip Paeps on
*gasp*!
Since when do "web developers" care about performance? Two seconds is hours of CPU time...
(obviously not a web
Submitted by Anonymous on
(obviously not a web developer.)
Great hint! Worked well! The
Submitted by claudiop on
Great hint! Worked well! The performance did improve! Thanks! Any other hints on NuSoap are welcommed!
Fantastic article about
Submitted by Dan on
Fantastic article about caching WSDL's!
Thanks for your post. This
Submitted by Craig on
Thanks for your post. This cut down my web service calls by 3 seconds.
So, does this cache the parsed WSDL or just the WSDL from the SOAP server? I've not been able to find any info on that.
It caches the parsed WSDL
Submitted by litrik on
It caches the parsed WSDL file. If you open the file that gets saved on disk you'll notice that it contains a PHP data structure.
Hi Thanks for this
Submitted by Dave on
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
Submitted by arnodmental on
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);
}
Hello. I tried your example
Submitted by Ro on
Hello. I tried your example for caching and where is it being cached? I can't find the file. Thanks!
The cached WSDL file is
Submitted by litrik on
The cached WSDL file is stored in your "files/tmp" directory. There are 2 files. Their names start with "wsdl-cache-".
Hello. I don't see it. How
Submitted by Anonymous on
Hello. I don't see it. How can I check to see if it even cached the WSDL? Thanks.
You will notice that the
Submitted by litrik on
You will notice that the WSDL has been cached if: performance is much better and/or you find the generated wsdl-cache files.
I am pretty new to web
Submitted by Anonymous on
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?
the answer is no. Also, did
Submitted by Anonymous on
the answer is no.
Also, did drastically improve the overall execution time since I had to make about 20-30 web service calls in a recent ETL script.
Now for some reason when I
Submitted by Anonymous on
Now for some reason when I get my wsdl from the cache the brackets are missing. Why is that? I get a xml parsing error.