PHP blocks session_start while other PHP instance is running

PHP blocks session_start while other PHP instance is running

am 02.04.2008 17:11:32 von Christoph

A while ago, I implemented an AJAX-based progress bar on a web page
that executed a lengthy server operation. The web page was a Java
servlet on a Tomcat server. The progress bar worked by repeatedly
querying a secondary "Status" servlet, which returned JSON information
about the progress of the ongoing server operation. The main servlet
communicated with the "Status" servlet through session variables, so
that the status servlet would know the progress of the main servlet's
operation.

Now I am trying to implement the same thing in a different application
in PHP (which I'm more familiar with than Java servlets). Technically,
the whole thing is functional: The main script launches, opens a
session with start_session, then updates the session variables with
the progress of the operation, while the jQuery-based page requests
progress updates from the second script.

However, a fatal flaw is rendering the whole set-up useless: The
server refuses to respond to the AJAX request until the server
operation is complete. While the main script is running, the second
script cannot loaded.

By experimenting a bit, I finally traced this to the "session_start"
command. It seems that while a PHP script is being executed (using
CGI) and has a session open, trying to re-open the same session in
another script will block the second request until the first script
has finished. So the session is useless for acting as a "semaphore" to
exchange information between the two scripts, which is exactly what I
need for my progress bar.

Is there any other possibility of exchanging such information, besides
a database? I'll use the database if I have to, but it seems like a
pretty big performance drag to have to read and write the progress to
and from the database almost every second.

--
Christoph

Re: PHP blocks session_start while other PHP instance is running

am 02.04.2008 19:04:58 von Shion

Christoph wrote:

> By experimenting a bit, I finally traced this to the "session_start"
> command. It seems that while a PHP script is being executed (using
> CGI) and has a session open, trying to re-open the same session in
> another script will block the second request until the first script
> has finished. So the session is useless for acting as a "semaphore" to
> exchange information between the two scripts, which is exactly what I
> need for my progress bar.

Not sure what file system you are using, it feels a bit like a limitation of
the file system, try to use a database based session, I think you will get a
lot more success that way.

If you don't want to use database, then I suggest you visit www.distrowatch.com


--

//Aho