PHP requires a queue

I have the following problem: when executing very simple PHP scripts, for example. this:

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

and open it on several tabs at the same time, the first tab ends after 10 seconds, but the seconds wait 20 seconds instead of 10, so I assume that the requests are β€œqueued” in some way. Any ideas how to get them to execute in parallel?

The 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 added

 KeepAlive On MaxKeepAliveRequests 0 MaxClients 512 MaxRequestsPerChild 100000 

in httpd.conf, but also, this is the default httpd.conf that comes with the lamp

+4
source share
4 answers

Most likely, this is a problem with the browser. Some browsers have a limit on the number of multiple connections to the same server. It seems that the presence of connection queues with two tabs seems low, so maybe this is another reason, but you should check the advanced settings for your browsers.

In addition, you may want to add an output stream after your echo functions and output something that can give you more information about what is happening - for example, server time.

Having a terminal window and closing the access log will also give you a better idea of ​​what is going on.

+1
source

This can 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 
0
source

When you use sessions, the second request cannot start using it before the first closes. Or you can use session_write_close() on the first, as soon as you no longer use any session variables.

0
source

Parts of the http.conf that you provided suggest that you can get some rewards by looking at this file in more detail (MaxKeepAliveRequests 0 - add a more reasonable limit here).

In particular, see how many servers you have running, for example

 StartServers 5 MinSpareServers 2 MaxSpareServers 8 ServerLimit 64 

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

  StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 
0
source

Source: https://habr.com/ru/post/1337242/


All Articles