Today is THE day I didn't find the answer I'm looking on the web (it never happened before). The fact is, I didn't find how to question google.
My problem : I run a PHP script "X" on my server (who need several hours) and I can't go to another page "Y" on the same server with Firefox.
But if I load page "Y" with Chrome, it works. How can I setup my server to launch several scripts (on the same server) with the same browser ?
This happens when you use sessions: When you run a script that uses a session, the session is locked. As the same browser is trying to access the same session, it will not work; the browser will have to wait until the session by the other tab / browser window is closed.
Possible solutions are for example:
Close the session as soon as possible / when you don't need it any more;
Don't use sessions for the long-running scripts;
Use different browsers / incognito mode so that the session information is not shared.
You're right.
I had to release the session lock in the scripts with "session_write_close() "and now it work.
Thanks for helping!
Related
Hoping someone has some ideas around what to do with this.
We have a application thats PHP based hosted in IIS.
There are a number of functions that need to run which can be running for 10mins+. The problem I have is that if I run one of these functions in my web browser. If I open another tab and try to access the site while that is happening then it just sits loading until the long process finishes and then it loads the page.
I guess this is more of a multi session thing to my browser? Is there some easy option in IIS I can change that will let it load the other pages as normal? Or is this a browser thing?
It seems if I open an in private window at the same time, that will load normally.
The issue is related to the session. by default PHP session use a file system.so that has to wait for the session file to be closed before they can open new. Therefore, subsequent requests for the same session wait on prior requests.
To resolve the issue you could try the below things:
-close the session when you are done with it by using the session_write_close()
-Implement a custom DB handler which utilizes the database instead of the file system.
Reference:
FastCGI on IIS7... multiple concurrent requests from same user session?
I'm having the strangest of problems with session variables that disappear.
First things first, Firefox is the only browser on which I see the problem. IE9 and Chrome are working just fine.
Now the context : after being loaded, my page starts performing Javascript XHR on my server every minute to refresh a status. Now, after a certain time (I've seen anywhere between 10 to 30 minutes), the request comes in to my php file, the session is started (with the same session ID as the previous request (same client of course)), but the session variable are all unset !!
Session timeout is at the default 24 minutes but every request updates a $_SESSION['time'] variable to keep the session alive.
So in short, the session should not expire and the proper session ID is traveling across, yet after a (rather random) period of time, the session variable are gone.
Any idea on what could cause that ?
Ok. So I've finally fond the cause of that mysterious problem. Everything is clear now.
My web hosting service was offering me to install a bugbase on my domain which I did.
The bugbase was installed in its own directory and was accessed on http://mydomain.com/bugbase
The catch is that the bugbase was PHP based and so is my actual site.
So because they were both on the same domain (mydomain.com), if I accessed both from the same browser, they would both share the same PHP Session. So logging out from one, would also kill the session of the other.
And voilĂ !!
Once I found that, I could confirm that the problem was seen in any browser where I opened both my site and the bugbase.
I have not tried yet, but the solution to the problem will probably be to install the bugbase on a subdomain.
In my Zend Application, I am trying to make our authenticated users be automatically logged out when they close their browser.
For that I'd write following code:
ini_set('session.cookie_lifetime', 0);
And its working fine on browsers like Chrome, Safari, IE7 and IE8, but in case of firefox, users still remain logged on when they close their browser.
Does anyone know what is causing problem?
Thanks In advance...
A value of 0 indicates "session cookie" - i.e. one that the browser should destroy when the "session" is over and the browser is closed.
However:
Different browsers have different interpretations of exactly what a "session" is - some will destroy these cookies when your close the tab, some when you close the window, some won't destroy the cookies until all instances of the browser have been closed - all tabs in all windows.
Since cookies are stored and transmitted by the client, they are completely the responsibility of the client. You should not rely on cookies alone to control whether a user has a valid login because they are ridiculously easy to spoof, you should implement some kind of activity timeout as well.
Make sure you have actually ended your Firefox session when testing - close all open tabs and windows, and watch the process list to ensure there are no instances left. If you are still having a problem, you are probably looking at some kind of bug in Firefox (or maybe you've made some strange change in about:config) and you need to ask for Firefox-specific help - SuperUser.com would be a better place for that. One thing you can be fairly sure of is that if it works everywhere else, it's not a problem with your PHP.
I'm not quite sure how to phrase this question correctly, so I'll start with the scenario I encountered.
I have a bit of processing in my web app that takes longer than I'd like the user to wait to have control of the page again, so I decided to have it processed by an ajax request.
The problem is, even though I offloaded this request into an ajax request, it seems that apache won't process any further requests until the original processor heavy request is complete.
I originally wanted to know how I could get around this issue, but have since decided that it might be a bad idea in general.
However, I'm still curious if anyone knows why apache behaves this way, and what (if any) configuration directive controls it. My original thought was KeepAlive, but disabling that didn't seem to change the behavior.
I am running php through mod_php if that makes a difference.
I appreciate any help getting pointed in the right direction!
Are you using file-based sessions? PHP will lock session files for each request and maintain that lock until you do a session_write_close() or the script terminates/exits. The side effect of this is that all requests become serial, since they're all contending for the same single resource (the session file).
I am sure it's the session file. I have the same problem. I run a request that is long such as a PHPMyAdmin SQL insert which takes multiple minutes to process. While it is processing I try to open a new tab in the same browser and go to any page on my website and it will not go there until the original PHPMyAdmin request is done.
If I open an incognito window in Chrome which is the same browser it works fine. If I open the website in any other browser it is fine.
So it is probably the file based session which is the default for PHP.
Others have mentioned going to memcached. You could also save sessions in the database.
Before having to go to memcached you could do all the session based stuff at the beginning. Copy the session variable into a temporary variable so you can close it then close it. And then if you need to set a session value later open it and make the change and then close it quickly.
Can you point to evidence that it's apache? Unless your apache setup isn't optimal, most likely your page wait is something else, maybe you have set your ajax call to be non-async?
I have a PHP site that makes use of sessions, which obviously are not supposed to be able to persist if you close your browser. I've done this scores of times, no issues.
And no issue currently - except within Microsoft's new Edge browser. If the user logs in, works in the site, closes Edge's window in the top right corner, and then re-opens the page and pastes the web address (or bookmarked it before), all their variables from the previous visit are still present. That's a problem, as each visit the viewer will likely want to give/lookup changing information.
I've successfully replicated the problem in Edge. What I can't figure out is why Edge is doing it. Every other browser kills the session and all its variables upon closing of the window (tested all the major browsers, including Internet Explorer). The only thing I can think of is Edge isn't actually closing as a program when the window is closing. Has anyone else ran into this problem? I can't find anything in the forums.
It is possible the session ended, but there is a bug with the cache.
I noticed that Edge is very aggressive with using cached pages. It would show a signed in page even after the user signed off (actually killing their session and updating the session cookie) because it would not respect the etag or any other cache instructions. I had to specifically prevent IE11 and Edge from caching at all.