- 论坛徽章:
- 0
|
自己已经处理了,把处理的结果分享给大家吧。
重点的变化在 destroy 方法- <?php
- class CSessFile {
- public function add( $key, $data, $cg_maxlifetime ) {
- $filepath = substr( $key, 7 );
- file_put_contents( SESSION_DIR.$filepath, $data );
- return true;
- }
- public function fetch( $key ) {
- $filepath = substr( $key, 7 );
- if ( !file_exists(SESSION_DIR.$filepath) ) {
- file_put_contents( SESSION_DIR.$filepath, '' );
- return true;
- }
- return file_get_contents( SESSION_DIR.$filepath );
- }
- public function delete( $key ) {
- $filepath = substr( $key, 7 );
- if ( file_exists( SESSION_DIR.$filepath ) ) {
- unlink( SESSION_DIR.$filepath );
- }
- return true;
- }
- };
- class CSessAPC {
- public function add( $key, $data, $cg_maxlifetime ) {
- apc_store( $key, $data, $cg_maxlifetime );
- return true;
- }
- public function fetch( $key ) {
- if ( !apc_exists( $key ) ) {
- apc_store( $key, '' );
- return true;
- }
- return apc_fetch( $key );
- }
- public function delete( $key ) {
- if ( apc_exists( $key ) ) {
- apc_delete( $key );
- }
- return true;
- }
- };
- class CSession {
- private static $engine;
- private static $gc_maxlifetime;
- public static function engine( $enginer ) {
- switch( $enginer ) {
- case 'apc':
- $handler = new CSession( new CSessAPC() );
- break;
-
- default:
- $handler = new CSession( new CSessFile() );
- break;
- }
- ini_set( "session.save_handler", "user" );
- ini_set( 'apc.ttl', 3600 );
- ini_set( 'apc.user_ttl', 1200 );
- ini_set( 'apc.gc_ttl', 3600 );
- session_set_save_handler(
- array($handler, 'open'),
- array($handler, 'close'),
- array($handler, 'read'),
- array($handler, 'write'),
- array($handler, 'destroy'),
- array($handler, 'gc')
- );
- }
- public function __construct( & $engine ) {
- self::$engine = $engine;
- self::$gc_maxlifetime = ini_get( 'session.gc_maxlifetime' );
- }
- public function read( $id ) {
- return self::$engine->fetch( 'session/'.$id );
- }
- public function write ( $id , $data ) {
- return self::$engine->add( 'session/'.$id, $data, self::$gc_maxlifetime );
- }
- public function close ( ) {
- return true;
- }
- public function destroy ( $id ) {
- return self::$engine->delete( 'session/'.$id );
- }
- public function __destruct ( ) {
- session_write_close();
- }
- public function gc ( $maxlifetime ) {
- return true;
- }
- public function open ( $save_path , $session_name ) {
- return true;
- }
- };
复制代码 |
|