Why cannot Apache handle multiple requests at the same time?

后端 未结 8 592
执笔经年
执笔经年 2021-01-31 21:23

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 pr

相关标签:
8条回答
  • 2021-01-31 21:30

    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

    0 讨论(0)
  • 2021-01-31 21:34

    Apache can surely handle multiple requests at the same time, there is something surely going wrong within your apache configuration.

    It depends on which version of Apache you are using and how it is configured, but a common default configuration uses multiple workers with multiple threads to handle simultaneous requests. See http://httpd.apache.org/docs/2.2/mod/worker.html for a rundown of how this works.

    The reason why you are facing it is: There is some lock somewhere - which can happen, for instance, if the two requests come from the same client, and you are using file-based sessions in PHP : while a script is being executed, the session is "locked", which means the server/client will have to wait until the first request is finished (and the file unlocked) to be able to use the file to open the session for the second user.

    The requests come from the same client AND the same browser; most browsers will queue the requests in this case, even when there is nothing server-side producing this behaviour.

    0 讨论(0)
  • 2021-01-31 21:34

    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.

    0 讨论(0)
  • 2021-01-31 21:38

    You can move session storing from files to database - than you would have possibility to request your files all at once without waiting - or - if you don't need session in your script turn it off (don't use session_start();)

    0 讨论(0)
  • 2021-01-31 21:44

    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.
    0 讨论(0)
  • 2021-01-31 21:46

    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.

    0 讨论(0)
提交回复
热议问题