<?php
class SessionSaveHandler
{
/**
* Constructs the object
*/
public function __construct()
{
/**
* Register the functions
*/
session_set_save_handler(
array($this, "open"),
array($this, "close"),
array($this, "read"),
array($this, "write"),
array($this, "destroy"),
array($this, "gc")
);
/**
* To call the write process before the object cache is destroyed
*/
register_shutdown_function('session_write_close');
}
/**
* Opens a connection - Not in use
*
* @param string $savePath
* @param string $sessionName
* @return boolean
*/
public function open($savePath, $sessionName)
{
return true;
}
/**
* Closing the connection - Not in use
*
* @return boolean
*/
public function close()
{
return true;
}
/**
* Returns the datas for the given session id
*
* @global WP_Object_Cache $wp_object_cache
* @param string $id
* @return mixed
*/
public function read($id)
{
global $memcachedConnection;
return $memcachedConnection->get($this->prepareId($id));
}
/**
* Saves the datas for the given session id
*
* @global WP_Object_Cache $wp_object_cache
* @param string $id
* @param mixed $data
*/
public function write($id, $data)
{
global $memcachedConnection;
$memcachedConnection->set($this->prepareId($id), $data, 3600);
return true;
}
/**
* Deletes the data for the given session id
*
* @global WP_Object_Cache $wp_object_cache
* @param string $id
*/
public function destroy($id)
{
global $memcachedConnection;
$memcachedConnection->delete($this->prepareId($id));
return true;
}
/**
* Garbage collection - not in use - we have no garbage!
*
* @param integer $maxlifetime
* @return boolean
*/
public function gc($maxlifetime)
{
return true;
}
/**
* Returns the id with a prefix
*
* @param string $id
* @return string
*/
protected function prepareId($id)
{
return 'SMK_' . md5($_SERVER['SERVER_NAME']) . '_SESSION_' . $id;
}
}
/**
* Creates the object and register the new session handler
*/
$sessionHandler = new SessionSaveHandler();
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/PXc7q on line 8
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/PXc7q on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/PXc7q on line 8
Process exited with code 255.