Re: [Webframework-general] Re: session manager
Status: Beta
Brought to you by:
staniszczak
From: maeve f. az-z. <mae...@ya...> - 2005-11-29 03:35:04
|
hi marcin, this my dbsessionhandler: <?php class DbSessionHandler implements ISessionHandler { const DB_HOST = 'localhost', DB_USERNAME = 'root', DB_PASSWORD = 'firefox', DB_DRIVER = '{SQL Server}', DB_DATABASE = 'zahra', /** * Connect to Db * * @return boolean */ private function getConnected() { return odbtp_connect(self::DB_HOST,'DRIVER='.self::DB_DRIVER.';SERVER='.self::DB_HOST.';UID='.self::DB_USERNAME.';PWD='.self::DB_PASSWORD.';DATABASE='.self::DB_DATABASE.';') or die('Connection to Db failed.'); } /** * Start session * * @access public * @param string path to the session's files directory * @param string session's name * @return boolean */ public function start($strPath, $strName) { $this->getConnected(); return true; } /** * stop session * * @access public * @return boolean */ public function stop() { return $this->gc(0); } /** * Read data from session * * @access public * @param string session ID * @return string value */ public function read($strID) { $strSQL = "exec readsession '$strID'"; $objQty = odbtp_query($strSQL); $strVal = ''; while ($arrRows = odbtp_fetch_array($objQty)) { $strVal = $arrRows['sessionvalue']; } return $strVal; } /** * Write data to session * * @access public * @param string session ID * @param string session data * @return boolean */ public function write($strID, $strValue) { $time = time(); $strSQL = "exec writesession '$strID', $time, $time, '$strValue'"; return odbtp_query($strSQL)?true:false; } /** * Session destroy * * @access public * @param string session ID * @return boolean */ public function destroy($strID) { $strSQL = "exec destroysession '$strID'"; return odbtp_query($strSQL)?true:false; } /** * garbage collection * * @access public * @param int session max life time * @return boolean */ public function gc($intMaxLifeTime) { $intLifeTime = strtotime('-1 minutes'); $strSQL = "exec deletesession $intLifeTime"; return odbtp_query($strSQL)?true:false; } } ?> this procedure for above code: create procedure readSession (@sessionid varchar(32)) as select sessionvalue from sessions where sessionid=@sessionid create procedure destroySession (@sessionid varchar(32)) as delete sessions where sessionid=@sessionid create procedure deleteSession (@sessionlife int) as delete sessions where sessiontime<@sessionlife create procedure insertSession (@sessionid varchar(32), @sessiontime int, @sessionstart int, @sessionvalue text) as insert into sessions (sessionid, sessiontime, sessionstart, sessionvalue) values (@sessionid, @sessiontime, @sessionstart, @sessionvalue) create procedure updateSession (@sessionid varchar(32), @sessiontime int, @sessionvalue text) as update sessions set sessiontime=@sessiontime, sessionvalue=@sessionvalue where sessionid=@sessionid create procedure writeSession (@sessionid varchar(32), @sessiontime int, @sessionstart int, @sessionvalue text) as if exists(select sessionid from sessions where sessionid=@sessionid) exec updateSession @sessionid, @sessiontime, @sessionvalue else exec insertSession @sessionid, @sessiontime, @sessionstart, @sessionvalue tia, ryan Marcin Staniszczak <mar...@ga...> wrote: Hi Ryan, Sorry for this bug - I correct it. Now I try this code with my old session handler, and all work fine. Why you manually call gc() method? gc() is automatically called by PHP, but with random frequency - see in php.ini session.gc_probability and session.gc_divisor./ But any way, when I call from my code in stop() manually gc(0), it work fine. Can you send my your session handler? I try test it and correct - if I found bug;-) web.framework with correct bug that you submit I submit to CVS. In next release this bug will by correct:-) Sorry for it and thanks for submit. Best regards, Marcin Staniszczak/ [kelembutan-Mu, menjawab doa-doa diam kami] --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. |