Forum Moderators: coopster

Message Too Old, No Replies

Tricky Sessions (locking?)

Using the same session across 3 different ajax calls.

         

ftaylor

11:00 pm on Nov 17, 2008 (gmt 0)

10+ Year Member



Hello,

I have a rather complicated situation with sessions on my website.

Picture this:

You load page x on my website and the session begins. When page x has "finished" loading, it begins am ajax loop that polls the server for updates to part of the content of the page. The technique used is "long polling"; javascript hits the server, and the server waits for about 15 seconds, constantly checking, and issues a reply instantly if there is any change. This script also calls session_start() to retrieve the session information.

On page x a user can also click one of a number of different form buttons that open a thickbox stuffed with an ajax loaded php form. These forms also call session_start() to retrieve the session information.

Here's the problem:

page x loads fine, script exits and the session lock is dropped. The ajax content is loaded fine, and the long poll loop begins again. If you try and open any of the forms, or even navigate to a different page, you have to wait for the long poll script to finish executing. I believe that the problem is that the long polling script locks the session, so when I try and open one of the forms, it has to wait to get a lock on the session in order to execute. The form is loaded in the thickbox, the script executes then exits and then the session is locked again in the background by the polling loop.

What can I do to "share" the session so that I do not have to wait for the polling loop to exit before I can use the session in another script?

I hope you can make sense of this!

Cheers,

Finbarr

ftaylor

11:24 pm on Nov 17, 2008 (gmt 0)

10+ Year Member



I found the solution to the problem!

session_write_close();

If you are using the same session concurrently in different scripts/pages/ajax/frames on your site, you can release the lock by calling session_write_close();, but you cannot alter any session variables within the calling script afterwards. This is to prevent data corruption caused by various scripts all trying to modify session variables at the same time.

Finbarr