4

I have the following problem: when executing very simple PHP scripts, e.g. this one:

<?php
echo "1";
sleep(10);
echo "2";
?>

and open it in multiple tabs simultaneously, the first tab finishes in 10 seconds, however the seconds waits 20 seconds instead of 10, so I'm guessing the requests are "queued" somehow. Any ideas how to make them execute in parallel?

Configuration is as follows: LAMP stack, Ubuntu 10.10 64bit; Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1

I have added

KeepAlive On
MaxKeepAliveRequests 0
MaxClients 512
MaxRequestsPerChild 100000

to httpd.conf, but besides that, it's the default httpd.conf that comes with lampp

9
  • 1
    either the tabs are screwing with you or your mis interpreting it, most sites have multiple visitors at once, imagine if this really was the case. Commented Jan 27, 2011 at 2:50
  • I realize that, however I think the problem is in my server configuration rather than the browser. Commented Jan 27, 2011 at 2:55
  • 1
    i don't know how to set up a sever to act in such a weird way, any out of the box are not going to act like that Commented Jan 27, 2011 at 2:59
  • I found out that this could be caused by session vars, however I have none, so it shouldn't be a problem Commented Jan 27, 2011 at 3:05
  • 3
    stackoverflow.com/questions/4653686/php-on-windows-and-blocks Commented Jan 27, 2011 at 3:15

4 Answers 4

1

Most likely its a browser issue. Some browsers have a limit on the number of multiple connections to the same server. Having queued connections with 2 tabs seems seems to low, so maybe its another reason but its worth checking out the advanced settings for your browsers.

Also, you may want to add output flushing after your echo functions and to output something which could give you more clues to whats happening - for example the server time.

Having a terminal window open and tailing the access log will also give you a better picture to whats happening.

Sign up to request clarification or add additional context in comments.

3 Comments

Every tabed browser I've seen gives each tab a new connection pool - and you'd need to find a very old browser which had a limit of 2 concurrent connections
Actually it appears the issue is something close to that. When I changed the URLs, the connections were concurrent alright. I didn't investigate further, because in a real life situation my specific situation wouldn't happen. Original credit goes to zerkms, however zaf is the closest to the real answer.
@KPetrov Thanks. If you can upvote to remove the tight downvote then that would spread some optimism rather than the opposite.
0

This might help:

  // function for small sleeps that dont take cpu cycles
  function microdelay($delay) {
    $UNUSED_PORT = 31238; //make sure this port isn't being used on your server
    @fsockopen("tcp://localhost", $UNUSED_PORT, $errno, $errstr, $delay);
  }

  microdelay(.5); //500ms
  microdelay(.25); //250ms
  microdelay(2.25); //2250ms

2 Comments

Interesting - but why do you think that a sleep call on a Unix system should cost CPU cycles?
I'm quite sure that I've read about it somewhere, but for now, could not find the source and seems I'm mistaken. :/
0

When you are using sessions a second request cannot start make use of it before the first one closes. Or you can use session_write_close() on the first one as soon as you don't make use of any session variables anymore.

Comments

0

The parts of the http.conf you've provided suggest that you may reap some rewards by looking at this file in a bit more details (MaxKeepAliveRequests 0 - put a more sensible limit here).

In particular, do have a look at the number of servers you have running, e.g.

StartServers       5
MinSpareServers    2
MaxSpareServers    8
ServerLimit       64

This is a conservative setup for development work on a local workstation. For very low volume concurrent access, it might look something like....

 StartServers       8
 MinSpareServers    5
 MaxSpareServers   20
 ServerLimit      256

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.