The question that prompted the discussion was along the lines of "The standard php sessions seem to use file locks to prevent concurrent usage, but there is no equivalent here (when a database is used to handle sessions)."
OMG!I am geek
Posts: 57
394 credits Members referred : 0
« Reply #2 on: May 23, 2007, 01:28:03 PM »
What do you think about the posted solution for the database locking problem?
Metal slug addict
Posts: 19
126 credits Members referred : 0
« Reply #3 on: May 23, 2007, 02:40:54 PM »
After looking at it in more detail it seems the problem only occurs if there are 2 overlapping accesses with the same session id
This usually doesn't happen. It does happen if a user opens more than one browser window (At least in Firefox) and browses different parts of the same website in each window. Or if the site is designed to use Frames.
Personally I find the solutions too complicated to risk incase they introduce other problems.
It might be worth giving some thought to what would be the worst that could happen in the Access_User class by using it in 2 simultaneaous windows. I have tried opening 2 windows and have seen in the database that they are sharing the same session row. When I log out of one and then try to do something in the other it prompts me to log in again. So the session has been corrupted but in a safe way. There might be other situations though that aren't so good?
Mike
OMG!I am geek
Posts: 57
394 credits Members referred : 0
« Reply #4 on: May 23, 2007, 02:52:45 PM »
I assumed the solution could protect a usual table locking problem. I mean if two users tries to read or write in the same database row. So you think this is not in that case?
Metal slug addict
Posts: 19
126 credits Members referred : 0
« Reply #5 on: May 23, 2007, 02:58:33 PM »
No that isn't a problem. Because if you have 2 users then they will have different session ids so they will be using different rows.
Unless one is a hacker of course
OMG!I am geek
Posts: 57
394 credits Members referred : 0
« Reply #6 on: May 23, 2007, 03:15:11 PM »
In an other case it could be a problem I think. For example the admin and a user try to insert something in users_profile table and there is no locking featcher, which data will be insert and shown at next?
I assume that problem could be solved by only allow only one user to edit/view the same row by checking if this row has an session for a tempoary insert which should be deleted afted the insert in done. What do you think of it?
« Last Edit: May 23, 2007, 03:22:27 PM by tomz »
Metal slug addict
Posts: 19
126 credits Members referred : 0
« Reply #7 on: May 23, 2007, 03:35:58 PM »
Quote
In an other case it could be a problem I think. For example the admin and a user try to insert something in users_profile table and there is no locking featcher, which data will be insert and shown at next?
Yes that could be a problem but it is a different problem.
I would think the best solution there would be for the admin to make sure that situation didn't occur. For example wait until they are logged off then deactivate the user, do the changes and re activate them.
Depends how often and how complicated the changes are I suppose.
Mike
OMG!I am geek
Posts: 57
394 credits Members referred : 0
... For example wait until they are logged off then deactivate the user, do the changes and re activate them.
Depends how often and how complicated the changes are I suppose.
Mike
I know it's an new case but it's importend enough to think about. I don't think that if would be a good way to wait until the user has loged out, it can take minutes. I think it's only nessesary to lock viewing/edditing the user until the admin has finished edding something.
Metal slug addict
Posts: 19
126 credits Members referred : 0
« Reply #9 on: May 23, 2007, 03:52:40 PM »
Quote
I think it's only nessesary to lock viewing/edditing the user until the admin has finished edding something.
You are right. Good luck in getting Olaf to change it
Mike
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6440
39464 credits Members referred : 374
It's time to use PHP5!
« Reply #10 on: May 23, 2007, 04:01:18 PM »
not sure, its a little strange that there is only one solution available to handle this kind of problem...
I don't like to replace an old script with another one, I guess I will check a second way to handle this...
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8249
42481 credits Members referred : 3
« Reply #11 on: May 23, 2007, 04:02:59 PM »
I think this is too much buzz for nothing. First of all a DBMS (the database you are using) locks table when writes anyway, so it is impossible to have a broken session. When you are using files for session handling php locks the files, because if the same session do a write request at the same time (which is not very possible, but still is possible) the problem could be huge, because a situation like this can even crash the server.
Now even if you lock the row while you are writing on it, the next request will fail so this doesn't solve anything. In my opinion the only way to solve this is by using UPDATE statements, and instead of having a serialized php array in your table, use a table with one field for every important variable. This way you wont have any troubles with this.
After looking at it in more detail it seems the problem only occurs if there are 2 overlapping accesses with the same session id
This usually doesn't happen. It does happen if a user opens more than one browser window (At least in Firefox) and browses different parts of the same website in each window. Or if the site is designed to use Frames.
Personally I find the solutions too complicated to risk incase they introduce other problems.
It might be worth giving some thought to what would be the worst that could happen in the Access_User class by using it in 2 simultaneaous windows. I have tried opening 2 windows and have seen in the database that they are sharing the same session row. When I log out of one and then try to do something in the other it prompts me to log in again. So the session has been corrupted but in a safe way. There might be other situations though that aren't so good?
I think this is too much buzz for nothing. First of all a DBMS (the database you are using) locks table when writes anyway, so it is impossible to have a broken session. When you are using files for session handling php locks the files, because if the same session do a write request at the same time (which is not very possible, but still is possible) the problem could be huge, because a situation like this can even crash the server.
Now even if you lock the row while you are writing on it, the next request will fail so this doesn't solve anything. In my opinion the only way to solve this is by using UPDATE statements, and instead of having a serialized php array in your table, use a table with one field for every important variable. This way you wont have any troubles with this.
I have that Idea too, and the whole item is not hot enough
I guess we need a file based safe session handling routine to use it on shared hosting platforms
Metal slug addict
Posts: 19
126 credits Members referred : 0
« Reply #14 on: May 23, 2007, 04:09:28 PM »
Quote
not sure, its a little strange that there is only one solution available to handle this kind of problem...
I don't like to replace an old script with another one, I guess I will check a second way to handle this...
Olaf, just to clarify. Tomz started talking about something completely different to this thread. His solution has nothing to do with the thread problem.
Mike
Metal slug addict
Posts: 19
126 credits Members referred : 0
« Reply #15 on: May 23, 2007, 04:13:32 PM »
Quote
I think this is too much buzz for nothing. First of all a DBMS (the database you are using) locks table when writes anyway, so it is impossible to have a broken session.
It is possible cos I did it. Just do the 2 window thing in Firefox.
Mike
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8249
42481 credits Members referred : 3
« Reply #16 on: May 23, 2007, 04:16:07 PM »
You did this with db driven sessions? And what was the problem?