read ( $id )

Read a session stored in DynamoDB

Part of the standard PHP session handler interface

Access

public

Parameters

Parameter

Type

Required

Description

$id

string

Required

The session ID.

Returns

Type

Description

string

The session data.

Source

Method defined in extensions/dynamodbsessionhandler.class.php | Toggle source view (50 lines) | View on GitHub

public function read($id)
{
    $result = '';

    // Get the session data from DynamoDB (acquire a lock if locking is enabled)
    if ($this->_session_locking)
    {
        $response = $this->_lock_and_read($id);
        $node_name = 'Attributes';
    }
    else
    {
        $response = $this->_dynamodb->get_item(array(
            'TableName'      => $this->_table_name,
            'Key'            => array('HashKeyElement' => $this->_dynamodb->attribute($this->_id($id))),
            'ConsistentRead' => $this->_consistent_reads,
        ));
        $node_name = 'Item';
    }

    if ($response && $response->isOK())
    {
        $item = array();

        // Get the data from the DynamoDB response
        if ($response->body->{$node_name})
        {
            foreach ($response->body->{$node_name}->children() as $key => $value)
            {
                $type = $value->children()->getName();
                $item[$key] = $value->{$type}->to_string();
            }
        }

        if (isset($item['expires']) && isset($item['data']))
        {
            // Check the expiration date before using
            if ($item['expires'] > time())
            {
                $result = $item['data'];
            }
            else
            {
                $this->destroy($id);
            }
        }
    }

    return $result;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback