Skip to content

Instantly share code, notes, and snippets.

@ericsk
Created December 30, 2013 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericsk/8183080 to your computer and use it in GitHub Desktop.
Save ericsk/8183080 to your computer and use it in GitHub Desktop.
WindowsAzureSessionHandler 的 Read 方法
/**
* Callback function for session handler. It's invoked while the session data is being read.
*
* @param $sessionId The session ID.
*
* @return string The session data. It will retrun empty string if the session doesn't exist.
*/
public function read($sessionId) {
try {
// try to retrieve the session content first to see if it exists
$result = $this->_tableRestProxy->getEntity($this->_sessionContainer, $this->_sessionContainerPartition, $sessionId);
// get the entity instance
$entity = $result->getEntity();
// deflat the serialized data
return unserialize(base64_decode($entity->getPropertyValue('data')));
} catch (ServiceException $e) {
// the entity doesn't exist, return empty string according to the spec:
// http://www.php.net/manual/en/sessionhandlerinterface.read.php
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment