Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 20th, 2018 84 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2.  
  3. // Native handlers
  4.  
  5. //ini_set('session.save_path', 'tcp://127.0.0.1:11211');
  6. //ini_set('session.save_handler', 'memcache');
  7.  
  8. //ini_set('session.save_path', '127.0.0.1:11211');
  9. //ini_set('session.save_handler', 'memcached');
  10.  
  11. // Custom handler
  12.  
  13. class FileSessionHandler
  14. {
  15.     private $savePath;
  16.  
  17.     function open($savePath, $sessionName)
  18.     {
  19.         $this->savePath = __DIR__.'/session';
  20.         if (!is_dir($this->savePath)) {
  21.             mkdir($this->savePath, 0777);
  22.         }        
  23.         return true;
  24.     }
  25.  
  26.     function close()
  27.     {
  28.         return true;
  29.     }
  30.  
  31.     function read($id)
  32.     {
  33.         return (string)@file_get_contents("$this->savePath/sess_$id");
  34.     }
  35.  
  36.     function write($id, $data)
  37.     {
  38.         var_dump('write() start '.date('His'));
  39.         sleep(2);
  40.         $ret = file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true;
  41.         sleep(2);
  42.         var_dump('write() end '.date('His'));
  43.         return $ret;
  44.     }
  45.  
  46.     function destroy($id)
  47.     {
  48.         $file = "$this->savePath/sess_$id";
  49.         if (file_exists($file)) {
  50.             unlink($file);
  51.         }
  52.  
  53.         return true;
  54.     }
  55.  
  56.     function gc($maxlifetime)
  57.     {
  58.         foreach (glob("$this->savePath/sess_*") as $file) {
  59.             if (filemtime($file) + $maxlifetime < time() && file_exists($file)) {
  60.                 unlink($file);
  61.             }
  62.         }
  63.  
  64.         return true;
  65.     }
  66. }
  67.  
  68. $handler = new FileSessionHandler();
  69. session_set_save_handler(
  70.     array($handler, 'open'),
  71.     array($handler, 'close'),
  72.     array($handler, 'read'),
  73.     array($handler, 'write'),
  74.     array($handler, 'destroy'),
  75.     array($handler, 'gc')
  76.     );
  77.  
  78. register_shutdown_function('session_write_close');
  79.  
  80. $start = session_start();
  81. var_dump('started '.date('His'));
  82.  
  83. var_dump(array(
  84.   'start'   => $start,
  85.   'session' => $_SESSION,
  86. ));
  87.  
  88. $key = isset($_GET['key']) ? $_GET['key'] : 'key';
  89. $data = isset($_GET['data']) ? $_GET['data'] : 'data';
  90.  
  91. var_dump('set '.date('His'));
  92. $_SESSION[$key] = $data;
  93.  
  94. var_dump('sleep '.date('His'));
  95. sleep(5);
  96. var_dump('sleep end '.date('His'));
  97.  
  98. var_dump($_SESSION);
  99.  
  100. var_dump('end of script '.date('His'));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top