Re: Custom database session handler and data concurrent access from ajax request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 3, 2007 4:45 am, n.quirin@xxxxxxx wrote:
> 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).

As noted in the user comments of the on-line manual, the sample code
in the manual does not (last I checked) handle the race condition of
multiple AJAX (or other) requests.

Several work-arounds are proposed, I believe.

> 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 more....Concurrent access does'nt seems to be safely managed
> natively...

Yes.

You *do* need to deal with this, and the sample code on php.net
doesn't do that.  It only works for the Web 1.0 (?) idea of
interaction with serial requests to alter session.

> Any idea? comment? I can sent my session handler php class....

Some kind of lock/mutex/whatever will be needed -- which will make
your AJAX calls serial, not parallel.

So you want to MINIMIZE your session writing section of code, call
session_write_close at the end of it, and do that as soon as possible
at the tip-top of the script, to make the serial-ness of the scripts
as low-impact as possible.

Also re-consider if you really really need to cram as much "stuff"
into a session as you originally architected.  Often-times I've seen
folks putting an awful lot of stuff in session data, and they don't
NEED to, it was just "convenient" -- Once you start down the AJAX
road, it seems to me like you want to re-think that "convenience" and
go for minimalism of what you write into a session.  But I ain't been
down that road, so maybe I'm full of it. :-)

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux