简体   繁体   English

在服务器端处理Web请求

[英]Handling web requests on server side

Situation: a user clicks on a link, the server gets the request and starts processing it. 情况:用户单击链接,服务器获取请求并开始处理它。 In the meanwhile, the user clicks on another link, the server gets the new request while processing the 1st one. 同时,用户单击另一个链接,服务器在处理第一个请求时会收到新请求。 What happens? 怎么了? On the client side we only see the webpage from the 2nd request, but is the process from the 1st request killed on the server when receiving the 2nd one? 在客户端,我们只能看到来自第二个请求的网页,但是在收到第二个请求时,服务器上的第一个请求的进程是否被杀死? And is it managed by the server or the language (Apache or PHP)? 它是由服务器还是由语言(Apache或PHP)管理的?

Depends. 要看。 If the browser does not drop the connection to server, it'll have absolutely no idea that the client has navigated elsewhere. 如果浏览器没有断开与服务器的连接,则绝对不会知道客户端已导航到其他位置。 If it does drop the connection, it's up to the Web server to choose to detect it and abort the processing thread or not. 如果确实断开了连接,则由Web服务器决定是否检测到连接并中止处理线程。

Either case, this is the nature of statelessness of HTTP. 无论哪种情况,这都是HTTP无状态的本质。 You shouldn't rely on anything in this regard. 在这方面,您不应该依赖任何东西。

Both requests get served (if the browser did send the second one). 两个请求均得到满足(如果浏览器确实发送了第二个请求)。

You would only see the second page, but if you'll look into access_log you'll surely notice two requests. 您只会看到第二页,但是如果您查看access_log,您肯定会注意到两个请求。

That's how HTTP works. 这就是HTTP的工作方式。

您可以使用ignore_user_abort()告诉脚本在连接终止后继续(或不继续)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM