views:

141

answers:

1

Hi,

I currently have a class Status, and I call it throughout my code as I preform various tasks, for example - when I upload an image, I call $statusHandler = new Status(121), when I resize it, I call $statusHandler = new Status(122). Every statusID corresponds to a certain text stored in the database. Class status retrieves the text, and stores in $_SESSION. I have another file, getstatus.php, that returns the current status. My idea was to call getstatus.php every 500 miliseconds with ajax (via jquery), and append the text to the webpage. This way the user gets (almost) real-time data about what calculations are going on in the background.

The problem is that I only seem to be getting the last status. I thought that it just was a result of things happening too quickly, so I ran sleep after calling new Status. This delayed the entire output of the page, meaning PHP didn't output any text until it completed running through the code. Does PHP echo data only after it finishes running through all the code, or does it do it real-time, line-by-line? If so, can anyone offer any workarounds so that I can achieve what I want?

Thanks.

+1  A: 

The default session implementation (flat file) sets a file lock on the session-file when session_start() is called. This lock is not released until the session mechanism shuts down, i.e. when the script has ended or session_write_close() is executed. Another request/thread that wants to access the same session has to wait until this lock has been released.

VolkerK
if i write session_write_close(), i won't be able to start it again, since headers have already been sent! any help with this?