Tuesday, June 29, 2010

Speeding up nuSoap Web Services - Caching wsdl files.

Good trick for speeding up Web Services Using nuSoap.

The latest project I worked on required the use of web services. If anyone has needed to interface with a web service who's wsdl file is massive this will help. I came across this...
http://www.norio.be/blog/2008/09/wsdl-caching-nusoap

--------------------------------------------------------------------
require_once('/lib/nusoap.php');
$url = 'http://example.com/test.wsdl';
$client = new nusoap_client($url, 'wsdl', '', '', '', '');

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','','','','');
----------------------------------------------------------------

Be sure the tmp dir is correct and writable. You can always do the simple check var_dump(is_dir(tmp));

This cut a few seconds off each web service call I made. I hope this helps!



Brian J. has been involved in web design since 1997. He is the founder of True Vision Computer Services, Inc. His recent focus has been on web applications and information systems development.

1 comment:

Anonymous said...

FYI - I've been using this WSDL cache method in production and it's improved load times for me as well, but it's come with a caveat.

The cache is too dumb basically. During a temporary upstream WSDL issue - it cached a 500 error response as the WSDL and caused all future SOAP calls to fail -- even after the upstream WSDL was back online.

Just be careful with how you use this -- I am still trying to figure out if I can reliably detect this scenario, or if I perhaps need to make it clear the cache every X requests.