Bug #13300 Updated: Calling of session write handler after output buffer sent is stupid!
| From: | basil dot hussain at kodakweddings dot com | Date: | Fri, 14 Sep 2001 14:07:39 +0000 |
| Subject: | Bug #13300 Updated: Calling of session write handler after output buffer sent is stupid! | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-65931@lists.php.net to get a copy of this message | ||
ID: 13300
User updated by: basil.hussain@kodakweddings.com
Reported By: basil.hussain@kodakweddings.com
Status: Open
Bug Type: Session related
Operating System: Linux
PHP Version: 4.0.5
New Comment:
For now, I have found a workaround in the case of storing session data in MySQL.
All you simply need to do in your write handler function is to issue a WRITE locking query before
the one that inserts/updates the session record and an unlocking query afterwards. This means that
the SELECT query issued from the session read handler in the page that was re-directed to happens,
it is queued until the session write from the previous page is finished.
So, instead of simply:
REPLACE INTO table_name (sess_id, mod_date, data) VALUES ('$sess_id', NOW(),
'$value');
You will have:
LOCK TABLES table_name WRITE;
REPLACE INTO table_name (sess_id, mod_date, data) VALUES ('$sess_id', NOW(),
'$value');
UNLOCK TABLES;
I'm sure this will seem obvious to some people, but I still think the current methodology is
flawed.
Previous Comments:
------------------------------------------------------------------------
[2001-09-14 07:55:43] basil.hussain@kodakweddings.com
I am experiencing the effects of bug #12968 too. However, it's not really a bug (as in there is
something malfunctioning), but rather a BIG design flaw. The whole thing centres around the
behaviour mentioned in the manual for the function session_set_save_handler():
"The 'write' handler is not executed until after the output stream is closed."
Because the output buffer is sent before the write handler is called, when the client browser is on
a fast network connection (i.e. an internal LAN in my case too) it recieves the output and acts upon
the 302 redirect HTTP header before the write handler has finished executing. However, in this case,
because we are using MySQL, the session write handler function takes some time - especially so when
your MySQL database is on a seperate host to the web server. This results in the page which is being
re-directed to executing in it's entirity (including the session read/write handlers) before
the original session write function finishes.
This is a MAJOR design flaw (nothing should ever rely upon the speed of a client connection), and I
move that this behaviour be changed immediately. The session write handler should be called before
the output buffer is sent, but still only after the script has finished executing.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=13300&edit=1