How does web server process the requests?(Web 服务器如何处理请求?)
问题描述
我使用 php 和 laravel 作为我的网络服务.
I use php and laravel as my web service.
我想知道在这些情况下 laravel 会存储和处理请求吗?
I want to know does laravel store and process requests in these situation?
- 许多用户对不同控制器的请求;
- 来自同一用户的对同一控制器的请求.
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 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 不直接处理请求,这是由您的网络服务器和 PHP 管理的.Laravel 收到一个已经被你的网络服务器处理过的请求,因为它只是一个用 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 服务器如何处理请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Web 服务器如何处理请求?
基础教程推荐
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 使用 PDO 转义列名 2021-01-01