Why cannot Apache handle multiple requests at the

2019-03-10 19:37发布

I have AMPPS installed.

My Apache server cannot handle multiple php requests at once (for example if I call localhost/script.php multiple times, they are processed in a consecutive order). script.php consists only of <?php sleep(10); ?>.

I read that MaxClients directive is responsible for concurrent access configuration, but it is missing in my httpd.conf at all.

Disabling Xdebug and writing session_write_close(); to the beginning of the script didn't work.

When I added session_start(); to the beginning of the file and my code looked like:

<?php

session_start();
session_write_close();
sleep(10);
phpinfo();

echo "Done";

When making 5 requests to localhost/script.php, last 4 waited for the first one to end and then ended concurrently.

Please, help me resolve the issue. If any information that is needed to help me resolve this problem is missing, please notify and I will add it.

标签: php apache ampps
8条回答
相关推荐>>
2楼-- · 2019-03-10 19:58

Probably becouse of sessions locking. When you don't need to edit session variables, close it.

http://php.net/manual/en/function.session-write-close.php

查看更多
Ridiculous、
3楼-- · 2019-03-10 20:02

manipulate yours sessions write on start of script.php

// manipulate writes, and unlock session file!
session_start();
$_SESSION['admin'] = 1;
$_SESSION['user'] = 'Username';
session_write_close(); // unlock session file, to another script can access

// start your script without php session block
sleep(30); 
echo $_SESSION['user'];

// another script can run without wait this script finish
查看更多
爷的心禁止访问
4楼-- · 2019-03-10 20:04

I encountered a similar problem. Multiple requests kept hanging randomly while connecting to the server.

Tried changing the mpm configurations, with no use.

Finally this one seems to solve the problem for me. (from https://serverfault.com/a/680075)

AcceptFilter http none
EnableSendfile Off 
EnableMMAP off 
查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-03-10 20:07

Have you tried to make the simultaneous calls with different browser tabs/windows/instances ?

Apache is multithreaded, so, it definitely can handle your parallel requests. It seems you have some things to check:

  • Make requests with an appropriate client for testing (like apache benchmark) - Take a look at https://httpd.apache.org/docs/2.4/programs/ab.html

  • Check your setup on apache. There is some wrong setups that can produce strange behavior, like single request at a time. Take a look at fork and worker parameters at httpd.conf. Suggestion: use all default parameters for testing.

查看更多
再贱就再见
6楼-- · 2019-03-10 20:11

Apache provides a variety of multi-processing modules (Apache calls these MPMs) that dictate how client requests are handled. Basically, this allows administrators to swap out its connection handling architecture easily. These are:

  1. mpm_prefork: This processing module spawns processes with a single thread each to handle request. Each child can handle a single connection at a time.
  2. mpm_worker: This module spawns processes that can each manage multiple threads. Each of these threads can handle a single connection.Since there are more threads than processes, this also means that new connections can immediately take a free thread instead of having to wait for a free process.
  3. mpm_event: This module is similar to the worker module in most situations, but is optimized to handle keep-alive connections. When using the worker MPM, a connection will hold a thread regardless of whether a request is actively being made for as long as the connection is kept alive.
查看更多
Bombasti
7楼-- · 2019-03-10 20:17

Try including the sleep and phpinfo within the session before calling session close. As it looks like the sessions(all the five are treated as same and are terminated with the first one being terminated). Maybe verify if the Session Ids are the same. By keeping the session open you can see that concurrently they are handled.

查看更多
登录 后发表回答