Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does apache not process multiple requests from the same browser simultaneously

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!

like image 635
Ben Mason Avatar asked Sep 02 '10 02:09

Ben Mason


2 Answers

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).

like image 58
Marc B Avatar answered Nov 07 '22 21:11

Marc B


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.

like image 25
PHPGuru Avatar answered Nov 07 '22 21:11

PHPGuru