Welcome to WebmasterWorld Guest from 107.20.104.110

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

nusoap 0.9.5

caching

     
9:24 am on May 3, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts: 383
votes: 0


I'm retrieving data from a webservice using nusoap. With a lot of trial and error I've managed to send and receive data. I'm now interested in enabling caching. I've searched google but none of the examples make sense. Would anyone be kind enough to tell me how enable for caching for the following call.


$s = new nusoap_client('https://api.example.com/API.asmx');
$msg = $s->serializeEnvelope($body);
$s -> send($msg,'https://api.example.com/API.asmx/CheckAvailability');
$response = $s->document;

Thank you in advance.
8:37 am on May 4, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts: 383
votes: 0


Bump ;)
4:08 pm on May 10, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts: 383
votes: 0


Anyone?
8:40 am on May 16, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts: 383
votes: 0


Last bump before it's off to join Experts Exchange ;)
12:42 pm on May 16, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Apr 30, 2007
posts:1394
votes: 0


Cache on what level? You want to cache the $body var contents? You want to cache the response, wsdl cache or what?
1:08 pm on May 16, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts: 383
votes: 0


Hi Enigma1

I want to cache the response, so basically if the same $body is requested within half an hour, the cached response is shown as opposed to making a new SOAP call.
6:25 pm on May 16, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Apr 30, 2007
posts:1394
votes: 0


In the nusoap library you should have a class called nusoap_wsdlcache. Here is some code

// Setup the requested url
$req = 'http://example.com/request.wsdl';
// Cache for half hour in the cache folder
$soap_cache = new nusoap_wsdlcache('/cache', 1800);
// Check if request is in cache
$soap_wsdl = $soap_cache->get($req);
// If not in cache make a record
if(empty($soap_wsdl)) {
$soap_wsdl = new wsdl($req);
$soap_cache->put($soap_wsdl);
}
// Create the client object
$soap_client = new nusoap_client($soap_wsdl, true);

So if the request is already cached it won't be recreated.
9:09 pm on May 17, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts: 383
votes: 0


Hi Enigma1

I understand that but just don't understand how to change the code below to work with caching.

$s = new nusoap_client('https://api.example.com/API.asmx');
$msg = $s->serializeEnvelope($body);
$s -> send($msg,'https://api.example.com/API.asmx/CheckAvailability');
$response = $s->document;
10:32 am on May 18, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Apr 30, 2007
posts:1394
votes: 0


The 'https://api.example.com/API.asmx'is effectively what should be in the $req variable above. Otherwise each time you construct the client the code will parse the wsdl.

Now for the specific response to be cached you could use a database or file and store the data. You could use a signature to reference the specific entry based on the request and retrieve it thereafter. For example:

$signature = md5($msg . 'https://api.example.com/API.asmx/CheckAvailability');
which can be used as a db column or filename so you can check if present and if it is retrieve its content without doing the "send"