note 118964 added to class.sessionhandler

From: Date: Wed, 09 Mar 2016 09:22:46 +0000
Subject: note 118964 added to class.sessionhandler
Groups: php.notes 
Request: Send a blank email to php-notes+get-205119@lists.php.net to get a copy of this message
Here is a wrapper to log in a file each session's operations. Useful to investigate sessions locks (which prevent PHP to serve simultaneous requests for a same client). Just change the file name at the end to dump logs where you want. class DumpSessionHandler extends SessionHandler { private $fich; public function __construct($fich) { $this->fich = $fich; } public function close() { $this->log('close'); return parent::close(); } public function create_sid() { $this->log('create_sid'); return parent::create_sid(); } public function destroy($session_id) { $this->log('destroy('.$session_id.')'); return parent::destroy($session_id); } public function gc($maxlifetime) { $this->log('close('.$maxlifetime.')'); return parent::gc($maxlifetime); } public function open($save_path, $session_name) { $this->log('open('.$save_path.', '.$session_name.')'); return parent::open($save_path, $session_name); } public function read($session_id) { $this->log('read('.$session_id.')'); return parent::read($session_id); } public function write($session_id, $session_data) { $this->log('write('.$session_id.', '.$session_data.')'); return parent::write($session_id, $session_data); } private function log($action) { $base_uri = explode('?', $_SERVER['REQUEST_URI'], 2)[0]; $hdl = fopen($this->fich, 'a'); fwrite($hdl, date('Y-m-d h:i:s').' '.$base_uri.' : '.$action."\n"); fclose($hdl); } } ini_set('session.save_handler', 'files'); $handler = new DumpSessionHandler('/path/to/dump_sessions.log'); session_set_save_handler($handler, true); ---- Server IP: 72.52.91.14 Probable Submitter: 81.255.99.49 ---- Manual Page -- http://php.net/manual/en/class.sessionhandler.php Edit -- https://master.php.net/note/edit/118964 Del: integrated -- https://master.php.net/note/delete/118964/integrated Del: useless -- https://master.php.net/note/delete/118964/useless Del: bad code -- https://master.php.net/note/delete/118964/bad+code Del: spam -- https://master.php.net/note/delete/118964/spam Del: non-english -- https://master.php.net/note/delete/118964/non-english Del: in docs -- https://master.php.net/note/delete/118964/in+docs Del: other reasons-- https://master.php.net/note/delete/118964 Reject -- https://master.php.net/note/reject/118964 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205119) next »