Web服务器(apache)如何在代码级别处理多个HTTP请求(how a web server(apache) handles multiple HTTP requests, on the code level)

希望这不是显而易见的事情,只是想澄清一些我不太确定的事情。 我在观看有关如何实现缓存的教程时遇到了这个问题。 似乎只是在服务器上添加一些全局缓存变量,将为所有客户端实现缓存。 我在Apache webserver中使用PHP。

我知道Web服务器可以接受多个客户端HTTP请求。 我的问题是Web服务器代码上发生了什么。

每次都执行相同的服务器代码吗? 意味着保留了一些全局变量? 或者,对于每个新的HTTP请求,都会创建一个新的代码实例。 如果是,那些多个实例是否已连接或可以以任何方式相互了解?

Hope this is not something obvious, just want to clarify some things I am not totally sure about. I got this question while watching a tutorial on how to implement caching. There is seems that just adding some global caching variables on the server, will implement caching for all clients. I use PHP with Apache webserver.

I know that a web-server can accept multiple client HTTP requests. My question is what happens on the web server code.

Is the same server code executed each time? Meaning that some global variables are preserved? Or for each new HTTP request, a new instance of the code is created. If yes, are those multiple instances connected or can be made aware of each other in any way?

最满意答案

坏消息是apache服务器本身不支持这种工作。 你必须使用像数据库这样的中间东西来处理这个问题。 然而,好消息是node.js以优雅的方式轻松完成这些工作:D

Bad news is the apache server does not native support for that kind of work. You have to use some intermediate stuff like database to handle this. However, good news is node.js do that stuff easily in an elegance way :D

更多推荐