Caching web service’s response
Posted by: kniganapolke 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.
Advertisement
Like this:
Be the first to like this post.