0

I'm running into an issue where AJAX requests from the same browser and client seem to be queued in chunks of 6 requests and I'm not able to determine why.

Here's the code I used to prove this is occurring.

<?php
if ( isset($_GET['index'])
    and isset($_GET['start']) ) {
    session_write_close();

    sleep(2);

    header('Content-Type: application/json');

    echo json_encode(
        array(
            'index' => $_GET['index'],
            'start' => $_GET['start']
        )
    );

    exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/jquery-1.12.4.min.js"></script>
<script language="javascript">
jQuery(window).load(function() {
    for(var i = 0; i < 10; i++) {
        jQuery.ajax({
            url: '/index.php',
            dataType: 'json',
            data: { index: i, start: Math.floor(Date.now() / 1000) },
            success: function(response) {
                console.log('Request '+response.index+', start: '+response.start+', end: '+Math.floor(Date.now() / 1000));
            }
        });
    }
});
</script>
</head>
<body></body>
</html>

Regardless of the PHP sleep time or inclusion of session_write_close(); on the server side, the responses come back staggered in groups of 6. Here's sample console log output from the above code with a line of delineation to show the delay.

(index):13 Request 0, start: 1472236910, end: 1472236912
(index):13 Request 1, start: 1472236910, end: 1472236912
(index):13 Request 2, start: 1472236910, end: 1472236912
(index):13 Request 3, start: 1472236910, end: 1472236912
(index):13 Request 4, start: 1472236910, end: 1472236912
(index):13 Request 5, start: 1472236910, end: 1472236912

----- Delay that matches the PHP sleep time after 6 responses -----    

(index):13 Request 6, start: 1472236910, end: 1472236914
(index):13 Request 7, start: 1472236910, end: 1472236914
(index):13 Request 9, start: 1472236910, end: 1472236914
(index):13 Request 8, start: 1472236910, end: 1472236914

I've verified that my Apache configuration doesn't have MaxClients specified so it should default to 256.

Any help would be greatly appreciated.

Barry Beerman
  • 303
  • 3
  • 9
  • Most browsers apply a limit to the number of concurrent requests against the same server, so this is likely to be that browser limitation for whatever browser you are using – Mark Baker Aug 26 '16 at 19:10
  • The browser also has a limit on the number of active requests it will send out. That number will vary between browsers. It's possible you're hitting your browsers max. – Mike Cluck Aug 26 '16 at 19:10
  • Is there a way to verify the browser is applying the limit? – Barry Beerman Aug 26 '16 at 19:16

1 Answers1

1

As other comments have pointed out, most web browsers limit concurrent requests to the same server, for many versions of IE and Firefox and even Chrome, this number is 6, which reflects the issue you are seeing. for reference: concurrent connections by browser

if you are in control of the browser, this setting can be changed either in your individual browser's settings or (in windows) in the registry itself. YMMV, please have a look for instructions how to do this if needed.

derelict
  • 2,044
  • 10
  • 15
  • 1
    A link only answer isn't very useful on StackOverflow. The idea is to provide the relevant information from the link that answers the question and include the reference material as a link (_in case the link is broken at a later time when someone else reviews this answer_). You also forgot to include the actual answer here. I would suggest posting this as a comment instead. – Sherif Aug 26 '16 at 19:17
  • You can add this as a comment and not an answer – Harshul Pandav Aug 26 '16 at 19:18
  • the answer is _most web browsers limit concurrent requests to the same server_; i added the link as evidence and reference. i guess it's bad form to actually provide an answer if i can just answer in comments? i'll add a bit of supportive info, but should i just delete my answer instead? – derelict Aug 26 '16 at 19:26
  • thanks, i get it -- still a bit of a noob to SE -- so after adding more to the answer and noticing it's marked duplicate anyway, should i delete the answer or leave it, and i guess i should probably delete all these comments since they don't add anything to the answer and just inform me how i can do this better... i really do want to know how best to self-moderate in this situation... thanks for the input! – derelict Aug 26 '16 at 21:00