views:

92

answers:

3

I have a website which has 2 pages , (home_page.php and action_page.php)Action page takes aprx. 2 minutes to completely load (server side takes 2 minutes) . But if user clicks to home page link while action page is loading , browser does not go to home page , until action page is completely loaded . First of all what is the reason of this ? (bowser ? php ? apache ?) and how can I avoid this ?

Thank you

+4  A: 

More than likely, it's because a session is locked. PHP will only allow one request per session to prevent issues coming up (overwriting data, etc). See: session_write_close()...

ircmaxell
Ok , i just added this function to the top of the action page and Right now it looks perfect .
Oguz
will it solve the problem of ajax calls too? If i make 2 ajax calls to same page then second ajax call will only be answered after first have finished processing. This happens only when session is enabled. When i remove session from the php page then either of the calls might respond first. Is this same peculiar behavior of php session?
Ayaz Alavi
Well, it's not a "peculiar" behavior, it's very wanted. There are two ways to avoid the issue. Either close your session as soon as you're done with it, or speed up your pages so even if there was a lock, it would only last for a tiny fraction of a second (and hence won't be noticed)...
ircmaxell
say i want to make reverse ajax app like directory uploader. One ajax call to app will start uploading directory that might take 1-2 hours so we dont expect response from that ajax call for long time. second ajax call will keep on polling server for the number of files that have been uploaded (that are updated in session by first ajax call continously). Problem is that second ajax call wont be able to read from session since first call is busy so that will keep second call busy too. How i might be able to use session so that it wont lock 2nd ajax call?
Ayaz Alavi
Open the session when you want to do the update, and then close it again right after...
ircmaxell
A: 

Does it work when you open a new tab instead of trying to remplace the current?

JeromeJ
also new tab does not load .
Oguz
A: 

If the page is taking 2 minutes to load, then you are reaching the network timeout limits of a typical browser. That is a really long time for a page to load. You may want to consider spawning a separate process to do handle the long processing. You can put the result in a database, file, etc and use polling to check if it's done.

When spawning a process (exec()), make sure you use nohup, background it (&) and direct error output to /dev/null, otherwise it won't disconnect from the web process, and the web process will wait for it to finish.

Brent Baisley