Web服务器如何处理请求? [英] How does web server process the requests?

查看:169
本文介绍了Web服务器如何处理请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用php和laravel作为我的Web服务.

I use php and laravel as my web service.

我想知道laravel在这种情况下是否存储和处理请求?

I want to know does laravel store and process requests in these situation?

  1. 从许多用户到不同控制器的请求;
  2. 向同一用户请求相同的控制器.

laravel是否按照请求到达的顺序将这些请求存储在队列中?

Is the laravel store these requests in a queue by the sequence the requests reached?

laravel并行处理请求是针对不同用户的,还是针对同一用户的顺序?

Is laravel parallel process requests for different users, and in sequence for the same user?

例如,有两个来自用户的请求.这两个请求将路由到同一控制器中的两个方法.虽然第一个请求将花费很长时间进行服务器端处理,但是第二个请求将花费很少的时间.当用户设置第一个请求时,尽管第二个请求花费的时间很少,但是第二个请求花费的时间很少,但是服务器端将不会处理第二个请求,直到它完成对第一个请求的处理为止.

For example, there are two requests from the user. The two requests route to two methods in the same controller. While the first request will cost a long time for the server side processing, the second one will cost very little time. When a user set up the first request then the second one, though the second one cost very little time, the the server side will not process the second request until it finish processing the first one.

所以我想知道laravel如何存储和处理请求?

So I want to know how does laravel store and process the requests?

推荐答案

Laravel不直接处理请求,这是由您的Web服务器和PHP管理的. Laravel收到您的Web服务器已经处理过的请求,因为它只是用PHP编写的工具,用于处理与请求调用相关的数据.因此,只要您的网络服务器知道如何执行PHP并调用适当的index.php文件,Laravel就会启动并处理从网络服务器接收到的请求数据.

Laravel does not process requests directly, this is something managed by your webserver and PHP. Laravel receives a request already processed by your webserver, because it is only a tool, written in PHP, which processes the data related to a request call. So, as long as your webserver knows how to execute PHP and calls the proper index.php file, Laravel will be booted and process the request data it receives from the webserver.

因此,如果您的网络服务器能够接收2个不同的调用(通常它们会成百上千个),它将尝试实例化2个PHP(子)进程,并且您应该在内存中并行运行2个Laravel实例.

So, if your webserver is able to receive 2 different calls (usually they do that in the hundreds), it will try to instantiate 2 PHP (sub)processes, and you should have 2 Laravel instances in memory running in parallel.

因此,如果您的代码依赖于其他代码,则可能需要很长时间才能执行,这取决于许多其他因素,因此您必须自己在Laravel应用中进行处理.

So if you have code which depend on anther code, which may take too long to execute depending on many other factors, you'll have to deal with that yourself, in your Laravel app.

我们通常要做的只是将数据添加到数据库中,然后从对数据存储中已有数据进行的计算中获得结果.因此,数据到达数据存储的顺序无关紧要,先进入哪个顺序,最终结果始终是相同的.如果您不能依靠这种方法,则必须准备您的应用程序以应对它.

What we usually do is to just add data to a database and then get a result back from a calculation done with data already in the datastore. So it should not matter the order the data get to the datastore, which one got in first, the end result is always the same. If you cannot rely on this kind of methodology, you'll have to prepare your app to deal with it.

这篇关于Web服务器如何处理请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆