Welcome to WebmasterWorld Guest from 54.221.119.45

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

nusoap 0.9.5

caching

     

gosman

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

10+ Year Member



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.

gosman

8:37 am on May 4, 2012 (gmt 0)

10+ Year Member



Bump ;)

gosman

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

10+ Year Member



Anyone?

gosman

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

10+ Year Member



Last bump before it's off to join Experts Exchange ;)

enigma1

12:42 pm on May 16, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Cache on what level? You want to cache the $body var contents? You want to cache the response, wsdl cache or what?

gosman

1:08 pm on May 16, 2012 (gmt 0)

10+ Year Member



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.

enigma1

6:25 pm on May 16, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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.

gosman

9:09 pm on May 17, 2012 (gmt 0)

10+ Year Member



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;

enigma1

10:32 am on May 18, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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"
 

Featured Threads

Hot Threads This Week

Hot Threads This Month