Kniganapolke Tech Blog

Caching web service’s response

Posted on: December 29, 2009

In my previous posts I showed how to authorize to a Sharepoint server and call it’s web services.
In my particular case I had to pull some lists from Sharepoint to show them on a web form. Authorization call + 3 WS calls took about 7 seconds to complete. So I decided to cache the lists to save 4 calls and to provide a separate form to update the lists.
The following code snippet serializes / deserializes a php array to / from a file.


// Call Sharepoint WS to het a list
/* array */ $result = $client->call("GetListItems", 
array("listName" => $list_guid, "viewName" => $view_guid,));
if($client->fault || !result){
	// Handle error
	return false;
}
// You may want to process the result for example to pick out only necessary fields
$data_array = processResult( /* array */ $result );
// Serialize data, put it to a file
file_put_contents($fileName, serialize($data_array), FILE_USE_INCLUDE_PATH);
	
// Deserialize data from a file into php array
$srlzd = file_get_contents($filePath, FILE_USE_INCLUDE_PATH);
$data_array = ($srlzd) ? unserialize($srlzd) : null;

I use Nusoap to call the web service.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


  • None
  • kniganapolke: Happy to hear that )))
  • Khuong: You save my life!!! I have been dealing with this for a whole week! When I was about to commit a suicide, you showed up and saved my life!!! Tha
  • kniganapolke: Thanks, your code seems to be more generic.

Categories

%d bloggers like this: