1

can someone please explain to me why is loading time of test.php?q=two 2 seconds, even though both "images" are loaded in parallel? Why has sleep in test.php?q=one effect on test.php?q=two ?

Proof that they are loading concurrently and that it takes second request twice as much time to finish:

parallel request

Code:

<?php
if (isset($_GET['q'])) sleep(1);
else{
?>
<img src="test.php?q=one">
<img src="test.php?q=two">
<?php
}
gadelat
  • 1,390
  • 1
  • 17
  • 25
  • Any chance you have `session.auto_start` set? – zerkms Dec 18 '14 at 21:22
  • I have session.auto_start set to 0 in php.ini – gadelat Dec 18 '14 at 21:27
  • And what if you check in `phpinfo()`? What is the configuration - php, webserver, SAPI. – zerkms Dec 18 '14 at 21:27
  • There is a [maximum number of parallel HTTP connections per server(domain?)](http://stackoverflow.com/a/14768266/1188035), but this wouldn't reach Chrome's limit of 6. I'm thinking there must be a limitation somewhere from Apache, PHP, or the browser. – sjagr Dec 18 '14 at 21:28
  • It's definitely off. http://pastebin.com/uZuxXB0T I don't think this is server misconfiguration. Does that snippet works differently for you? – gadelat Dec 18 '14 at 21:31
  • @gadelat: yep, it works fine for me. https://www.dropbox.com/s/095qcaurzaahhf7/Screenshot%202014-12-19%2010.34.04.png?dl=0 – zerkms Dec 18 '14 at 21:33
  • `test.php:1` is one byte smaller than `test.php:2` — so something is obviously getting added the second time around. – l'L'l Dec 18 '14 at 21:34
  • @l'L'l: there are several dynamic headers in response, like `Date` – zerkms Dec 18 '14 at 21:35
  • 1
    Call me crazy, but can you reproduce this from another ISP? ISPs like to do weird things (block ports, restrict simultaneous connections, etc. because they can.) Hotspot your phone and see if it still persists. Or are you doing this on your local environment? – sjagr Dec 18 '14 at 21:44
  • Yup I'm doing this locally in ArchLinux. But you are right guys, I tried same script in windows VM and it works fine there. So it's definitely not a problem of code. – gadelat Dec 18 '14 at 21:51
  • @gadelat What does your `httpd.conf` look like? – sjagr Dec 18 '14 at 21:53
  • The only reason `two` takes longer is because you've got $q set to sleep(1) twice by the time it gets to the second . Try flip-flopping `q=one` with `q=two`, you'll get the same result. – l'L'l Dec 18 '14 at 21:54
  • httpd.conf http://pastebin.com/Xf3wimAf – gadelat Dec 18 '14 at 21:58
  • @l'L'l Wat? The if-condition depends on `isset($_GET['q'])`... not content specific – sjagr Dec 18 '14 at 22:02
  • According to the code shown it's loading in succession, not parallel - big difference. – l'L'l Dec 18 '14 at 22:03
  • @l'L'l: according to the code it must load in parallel, and it does on my machine. The code **IS** fine. – zerkms Dec 19 '14 at 01:32
  • `` is called before `` — that **IS NOT** parallel, that is succession, as in one then two... – l'L'l Dec 19 '14 at 03:13

2 Answers2

0

Maybe you have a limit connections per IP

<IfModule mod_limitipconn.c>
     <Location /your-download-directory>
          MaxConnPerIP 1
     </Location>
</IfModule>
Noogic
  • 143
  • 5
  • I don't. $ grep MaxConnPerIP . -ri returns no matches. Config /etc/httpd/config/extra/httpd-mpm.conf is interesting though http://pastebin.com/bYkfz099 – gadelat Dec 18 '14 at 22:09
-2

Might also be because this script is in a file called test.php - self-calling? If so, on the first call the q is not set, on the second one it is, and that's why you get a delay of 1 second.

First call (page load itself) goes without q being set and the else logic is executed, second call goes with q=one and the if logic is executed (there should be no image output) and a delay of one second occurs, the third call goes with q=two, again the if logic is executed, no image output and a delay of one additional second occurs.

ZurabWeb
  • 1,241
  • 1
  • 12
  • 21
  • What is special in "self-calling"? Not to say there is no such a thing like "self-calling" and http requests are stateless – zerkms Dec 18 '14 at 21:24
  • "First call (page load itself) goes without q being set and the else logic is execute" --- no, this is completely wrong. You don't understand how php and http work, sorry. – zerkms Dec 18 '14 at 21:27
  • Well what I see form the code is PHP runs the command requested, that's `sleep(1)` on each call where `q` is set. That delays the response from PHP, and images are rendered one by one by the browser, not yet sure why. – ZurabWeb Dec 18 '14 at 21:29
  • that's right. It doesn't explain why they are not running in parallel. Your answer is based on a **WRONG** assumption on how php+html works. "not yet sure why" --- that is the question. – zerkms Dec 18 '14 at 21:29
  • @zerkms would you please stop attacking me while I'm trying to help YOU out? – ZurabWeb Dec 18 '14 at 21:31
  • Well, your answer is based on wild assumptions (which are incorrect). Anyway, I don't care, have fun. – zerkms Dec 18 '14 at 21:33
  • The issue might be caused because the browsers are single threaded, have a look at this article: http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/. P.S. I'm already having fun, thx. – ZurabWeb Dec 18 '14 at 21:33
  • Nope, browsers **ARE NOT** single threaded. Browsers fetch resources in parallel without any issues. Please stop guessing. – zerkms Dec 18 '14 at 21:36
  • What about PHP being limited to one process per script? – ZurabWeb Dec 18 '14 at 21:39
  • 1
    "PHP being limited to one process per script" --- this phrase makes no sense. – zerkms Dec 18 '14 at 21:41
  • To clarify, this is what I'm referring to: http://httpd.apache.org/docs/2.2/mod/worker.html. If you limit MaxSpareThreads and ThreadsPerChild to 1, it might lead to PHP running as "single-threaded". – ZurabWeb Dec 18 '14 at 21:43
  • you're referring to the things you don't understand. The phrase still makes no sense. Sorry, I'm out of this. – zerkms Dec 18 '14 at 21:44
  • 1
    It is clear enough for me that the whole answer and this discussion is pointless. – zerkms Dec 18 '14 at 21:47