anishmsry — 2010-03-30T03:25:14-04:00 — #1
i want to store sessions in mysql tables using session_set_save_handler function.
While reading some articles i came across the fact that while sessions are stored in files, the sessions are locked, but when sessions are stored in mysql using custom functions, sessions are not locked.
i also read that when sessions are stored in mysql using custom functions there will be problems when 2 persons simultaneously access the sessions.
is this issue solved in the latest versions of php?
or is there still problems of session locking?
smftre — 2010-03-30T05:21:53-04:00 — #2
Are you sharing the sessions? As that is not really allowed.
anishmsry — 2010-03-30T05:30:48-04:00 — #3
smftre — 2010-03-30T05:37:23-04:00 — #4
Are you trying to access the session at the same time by 2 different scripts?
hash — 2010-03-30T05:43:19-04:00 — #5
First off, why do you need to do this? Perhaps a better description will garner some decent responses, but for the most part what you are wanting to do is not necessary.
Secondly, it is not about the lock so much as two clients simultaneously accessing the session: regardless of locks, you have will likely have no way to know which does what first. If script1.php sets admin false and script2.php sets admin true, and you run both at once (via frames/ajax/whatever) then admin will be true or false based solely on which script finishes execution last.
anishmsry — 2010-03-30T06:06:12-04:00 — #6
it's for users logging in.
the thing which i've doubt is: if 2 users having 2 different session ids, access a page at the same time in which there is a script to modify the session data. Will it change the value of the other person's session data accidentally if sessions are stored in mysql.
anishmsry — 2010-03-30T06:07:03-04:00 — #7
is there session locking for sessions stored in database in the latest versions of php?
smftre — 2010-03-30T06:07:29-04:00 — #8
It should never modify each other's session data, as you are not overwriting it, each one is unique
anishmsry — 2010-03-30T06:17:25-04:00 — #9
does the latest versions of php support session locking for sessions stored in database (using session_set_save_handler)?
hash — 2010-03-30T06:20:09-04:00 — #10
if you have two different ids then how can they be equal; you can't modify two records when using a unique key.
No, php can't write your sql queries for you. The only thing php does with session handling is make sure session_write is done after the script loads.
php doesn't support sessions stored in a database. It supports it's default (file storage), or you taking over and doing what you want.
smftre — 2010-03-30T06:20:53-04:00 — #11
anishmsry — 2010-03-30T06:27:14-04:00 — #12
thanks a lot guys for replying....i was just wondering, how does php generate the session id - PHPSESSID? What are the parameters used for generating this hash?
immerse — 2010-03-30T07:54:04-04:00 — #13
How PHP generates the session id? No idea, but it provides this function:
crmalibu — 2010-03-30T10:24:59-04:00 — #14
It is a hash of REMOTE_ADDR(ip) and the current microtime, with optional entropy from a file.
anishmsry — 2010-03-30T11:22:28-04:00 — #15
hmm....i never thought REMOTE_ADDR(ip) will be used as a part to generate the PHPSESSID