garbage_collect ( $maxlifetime )

Performs garbage collection on the sessions stored in the DynamoDB table.

Part of the standard PHP session handler interface.

Access

public

Parameters

Parameter

Type

Required

Description

$maxlifetime

integer

Optional

The value of session.gc_maxlifetime. Ignored.

Returns

Type

Description

boolean

Whether or not the operation succeeded.

Source

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

public function garbage_collect($maxlifetime = null)
{
    // Send a search request to DynamoDB looking for expired sessions
    $response = $this->_dynamodb->scan(array(
        'TableName'  => $this->_table_name,
        'ScanFilter' => array('expires' => array(
            'AttributeValueList' => array($this->_dynamodb->attribute(time())),
            'ComparisonOperator' => AmazonDynamoDB::CONDITION_LESS_THAN,
        )),
    ));

    // Delete the expired sessions
    if ($response->isOK())
    {
        $deleted = array();

        // Get the ID of and delete each session that is expired
        foreach ($response->body->Items as $item)
        {
            $id = (string) $item->{$this->_hash_key}->{AmazonDynamoDB::TYPE_STRING};
            $deleted[$id] = $this->destroy($id, true);
        }

        // Return true if all of the expired sessions were deleted
        return (array_sum($deleted) === count($deleted));
    }

    return false;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback