Source for file msession.php
Documentation is available at msession.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> |
// +----------------------------------------------------------------------+
// $Id: msession.php,v 1.8 2005/01/26 09:47:28 dufuz Exp $
require_once 'Cache/Container.php';
* Stores cache contents in msessions.
* WARNING: experimental, untested
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
* @version $Id: msession.php,v 1.8 2005/01/26 09:47:28 dufuz Exp $
* Length of the Cache-Identifier
* Note that the PEAR-Cache prefixes the ID with an md5() value
* of the cache-group. A good value for the id_length
* depends on the maximum number of entries per cache group.
* Use msession_uniq to create a unique SID.
* Establish a connection to a msession server?
* mesession server connection
if ($this->host == null ) {
new Cache_Error('No host specified.', __FILE__ , __LINE__ );
if ($this->port == null ) {
new Cache_Error('No port specified.', __FILE__ , __LINE__ );
if (!($this->ms = msession_connect ($this->host, $this->port))) {
new Cache_Error('Can not connect to the sever using host "' . $this->host . '" on port "' . $this->port . '"', __FILE__ , __LINE__ );
function fetch($id, $group)
$group = msession_get ($id, '_pear_cache_data', null );
return array (null , null , null );
return array ($data['expires'], $data['cachedata'], $data['userdata']);
* WARNING: If you supply userdata it must not contain any linebreaks,
* otherwise it will break the filestructure.
function save($id, $cachedata, $expires, $group, $userdata)
$cachedata = $this->encode($cachedata);
'cachedata' => $cachedata,
'expires' => $expires_abs,
if (!msession_set ($id, '_pear_cache', true )) {
return new Cache_Error("Can't write cache data.", __FILE__ , __LINE__ );
if (!msession_set ($id, '_pear_cache_data', $data)) {
return new Cache_Error("Can't write cache data.", __FILE__ , __LINE__ );
if (!msession_set ($id, '_pear_cache_group', $group)) {
return new Cache_Error("Can't write cache data.", __FILE__ , __LINE__ );
if (!msession_set ($id, '_pear_cache_size', $size)) {
return new Cache_Error("Can't write cache data.", __FILE__ , __LINE__ );
// let msession do some GC as well
// note that msession works different from the PEAR Cache.
// msession deletes an entry if it has not been used for n-seconds.
// PEAR Cache deletes after n-seconds.
msession_timeout ($id, $expires);
$sessions = msession_find ('_pear_cache_group', $group);
foreach ($sessions as $k => $id)
return (msession_get (strtoupper(md5($group)) . $id, '_pear_cache_group', null ) == null ) ? false : true;
* Deletes all expired files.
* Note: garbage collection should cause lot's of network traffic.
* @param integer Maximum lifetime in seconds of an no longer used/touched entry
$sessions = msession_find ('_pear_cache', true );
foreach ($sessions as $k => $id) {
$data = msession_get ($id, '_pear_cache_data', null );
if ($data['expires'] <= time()) {
$size = msession_get ($id, '_pear_cache_size', null );
$entries[$data['expires']] = array ($id, $size);
while ($total > $this->lowwater && list ($expires, $entry) = each($entries)) {
msession_destroy ($entry[0 ]);
} // end func garbageCollection
Documentation generated on Mon, 11 Mar 2019 15:25:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|