2

I've tested the script below in Firefox 39.0 and Google Chrome 43.0:

<?php
print "Start time: " . date("H:i:s");
sleep(3);

I've tested it both locally (under WAMP - Apache/2.4.9, PHP/5.5.12 ) and on a remote host (under Ubuntu, Apache/2.2.17, PHP/5.3.5).

It seems that even though I perform two parallel requests they are not served/processed in parallel (the "second" request is delayed by 3 seconds).

I know that this usually happens when using sessions (due to the session locking mechanism), but given that I'm not using any sessions how come the requests are serialized?

Is there anything else that I could check for?

Note: the value of session.auto_start is OFF

Note: I noticed in Firefox, that if I disable the cache (browser's cache) I no longer encounter this. It might be related to Multiple Ajax requests for same URL and to Chrome treating smart url and causing concurrent requests pend for each other

Community
  • 1
  • 1
Razvan
  • 2,436
  • 18
  • 23
  • Apache could be imposing a limit: http://stackoverflow.com/questions/3389496/how-do-you-increase-the-max-number-of-concurrent-connections-in-apache – MonkeyZeus Jul 20 '15 at 14:44
  • maybe it's off in the .ini file, but it can easily be started in some OTHER .ini file, .htaccess/httpd.conf php_value directive, or even a session_start() in some file you're including. If you're on 5.4+, check `session_status()` – Marc B Jul 20 '15 at 14:45
  • @MarcB OP has indicated the exact code which they are testing. `session_start()` seems unlikely but I do agree with the other stuff – MonkeyZeus Jul 20 '15 at 14:46
  • session_status() returns 1 (which means that the session is not started) – Razvan Jul 20 '15 at 14:47
  • @MonkeyZeus: doesn't matter, there's `auto_prepend_file` as well. – Marc B Jul 20 '15 at 14:47
  • @MarcB Good point, I forgot about that – MonkeyZeus Jul 20 '15 at 14:48
  • There's no AJAX call. I request the file directly from the browser (http://localhost/test.php) in two different tabs. – Razvan Jul 20 '15 at 14:51
  • @Razvan What happens if you request it in Chrome and FireFox at the same time? – MonkeyZeus Jul 20 '15 at 14:54
  • It works fine. It also works fine if I disable cache on Firefox (using Web Developer toolbar). – Razvan Jul 20 '15 at 14:55
  • What if you have two different files, test1.php and test2.php, with the same code and request the two files in the same browser? – MonkeyZeus Jul 20 '15 at 14:57
  • It works fine. And it works fine even if I append any different query string to the end of the URL (this is why I think the cause is actually related to the way the two browsers work - see the two links in my question). – Razvan Jul 20 '15 at 14:59
  • Does Internet Explorer have this issue? – MonkeyZeus Jul 20 '15 at 15:01
  • Strangely, it seems that it doesn't have this issue. In Internet Explorer 9.0 it works fine. – Razvan Jul 20 '15 at 15:04
  • the page you are loading only has the code you posted above correct? – cmorrissey Jul 20 '15 at 15:05
  • Correct, that's the only code from the script. – Razvan Jul 20 '15 at 15:07
  • This may sound crazy but what if you set `sleep(15);` and check your times, it was taking me about 2-3 seconds to switch tabs and refresh the same page so it seemed like the browser was locking – cmorrissey Jul 20 '15 at 15:14
  • If you use Chrome's networking tools then is it downloading fresh or is it doing some "From Cache" process? http://i.stack.imgur.com/DvimR.png If it is from cache then you might have some headers being set incorrectly – MonkeyZeus Jul 20 '15 at 15:14
  • @cmorrissey: The delay is now of 15 seconds between the requests. – Razvan Jul 20 '15 at 15:18
  • @MonkeyZeus: the request is not cached (it's a fresh response). – Razvan Jul 20 '15 at 15:18
  • I know you are saying its not session locking but have you tried `session_write_close();` ? – cmorrissey Jul 20 '15 at 15:20
  • Yes, I even tried session_start(); and then session_write_close(); - but, regardless, I'm almost sure that this was actually related to the browser behavior (as you can see, Internet Explorer, behaves differently - so it is a browser issue). – Razvan Jul 20 '15 at 15:21
  • **I am able to consistently reproduce this issue in both Chrome and FireFox but IE is not suffering from this.** I used `sleep(10);` to make sure I gave myself adequate time to press refresh in both tabs. Call 1 takes 10 seconds and call 2 takes about 20 – MonkeyZeus Jul 20 '15 at 15:23
  • got me then, the onlything I can think of is the max parallel connections http://stackoverflow.com/questions/985431/max-parallel-http-connections-in-a-browser – cmorrissey Jul 20 '15 at 15:23
  • Using `for($i=0; $i<100000000; ++$i){}` produces the same non-parallel code execution delay in which the second request is waiting for the first one to finish. – MonkeyZeus Jul 20 '15 at 15:30

0 Answers0