[PHP] Custom database session handler and data concurrent access from ajax request
Hi, i'm currently working on a web site that use AJAX requests to load a web page by part. So, my apache server gives quickly an answer and current client must wait a little bit in order to have the entire web page, but while this loading step, he can already see my partially displayed web page and use it! This web site uses php session, based on cookies, but not only cookies (cookies are just prefered). session.auto_start is false in order to allow object declarations before session starts (so I can stored little object in session) There is no session handler defined in php.ini, line has been commented). In each php script, i start manually the session with session_start and i use register_shutdown to register session_write_close in order to write current session when the current script is finished. Sessions are managed in a mysql database, with autocommit enabled. I'm using mysql_pconnect in my handler to read/write session data (same user, same password, same host, always). Read/write session into database works...but not fine. Scenario: scripts are parts of a main page, scripts are called by ASYNC AJAX GET Script 1 modifies an object A from session and re-serializes it into session, Script 2 is launched when client is receiving a response from the server for script 1(php output buffering is enabled), Script 2 displayed object A content from session and flush object A content, re-serializes it into session, but sometime Script 2 doesn't displayed object A modification by script 1. More terrible, reloading the entire page displays all the content of the modified object A (but script 2 has flushed its content!) I'm asking if custom session handler must implement mutex system or anything to prevent concurrent access and terrible random errors of session writing/reading and moreConcurrent access does'nt seems to be safely managed natively... Any idea? comment? I can sent my session handler php class -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Custom session save handler. What's happens really?
Hi, i'm using in each script: When are exactly called the write and read function of my custom handler? Is it at the session_start that read function is called? or is it at $object = unserialize($_SESSION['objectname'])? Is write function called at session_write_close only? or any time $_SESSION[] is writted? Thanks a lot, I have no clue from PHP tutorial about this... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Custom session save handler. What's happens really?
Thanks, but I serialize and unserialize the objects and this is not my problem...(I known best practices for php5 about object serialization). Please read again the post. Selon itoctopus <[EMAIL PROTECTED]>: > You have to explicitly serialize and unserialize the objects. > I think the confusion here is with the automatic __wakeup and __sleep > functions: > http://www.devshed.com/c/a/PHP/Using-the-Sleep-and-Wakeup-Functions-to-Serialize-Objects-in-PHP/ > > > -- > itoctopus - http://www.itoctopus.com > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Hi, > > > > i'm using in each script: > > > > > session_set_save_handler(...); //register my custom function to store > > session > > //into a mysql database > > > > session_start(); //session.auto_start is set to 0 in php.ini > > register_shutdown("session_write_close"); > > > > $object = unserialize($_SESSION['objectname']); > > //modify the object > > // > > $_SESSION['objectname'] = serialize($object); > > ?> > > > > When are exactly called the write and read function of my custom handler? > > Is it at the session_start that read function is called? > > or is it at $object = unserialize($_SESSION['objectname'])? > > > > Is write function called at session_write_close only? > > or any time $_SESSION[] is writted? > > > > Thanks a lot, I have no clue from PHP tutorial about this... > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php