I use php and laravel as my web service.
我使用php和laravel作为我的Web服务。
I want to know does laravel store and process requests in these situation?
我想知道在这些情况下laravel存储和处理请求吗?
- requests to different controllers from many users;
- 向许多用户请求不同的控制器;
- requests to the same controller from the same user.
- 向同一用户请求同一控制器。
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?
laravel是否为不同的用户并行处理请求,并按顺序为同一个用户?
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.
例如,用户有两个请求。这两个请求路由到同一个控制器中的两个方法。虽然第一个请求将花费很长时间进行服务器端处理,但第二个请求将花费很少的时间。当用户设置第一个请求然后设置第二个请求时,尽管第二个请求花费很少的时间,服务器端将不会处理第二个请求,直到它完成处理第一个请求。
So I want to know how does laravel store and process the requests?
所以我想知道laravel如何存储和处理请求?
2 个解决方案
#1
20
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.
Laravel不直接处理请求,这是由您的Web服务器和PHP管理的。 Laravel收到您的网络服务器已经处理过的请求,因为它只是一个用PHP编写的工具,它处理与请求调用相关的数据。因此,只要您的Web服务器知道如何执行PHP并调用正确的index.php文件,Laravel就会被启动并处理它从Web服务器接收的请求数据。
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.
因此,如果您的Web服务器能够接收2个不同的调用(通常它们会执行数百个调用),它将尝试实例化2个PHP(子)进程,并且您应该在内存中并行运行2个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.
因此,如果您有依赖于其他代码的代码,这些代码可能需要很长时间才能执行,您需要在Laravel应用程序中自行处理。
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.
我们通常做的只是将数据添加到数据库,然后从使用数据存储区中的数据完成的计算中获得结果。因此,数据到达数据存储区的顺序无关紧要,首先进入数据存储区,最终结果始终相同。如果你不能依赖这种方法,你必须准备你的应用程序来处理它。
#2
2
Everything in PHP starts as a separate process. These processes are independent form each other until some shared resource comes in Picture.
PHP中的所有内容都作为一个单独的进程启动。这些进程彼此独立,直到某些共享资源出现在Picture中。
In your case one user is handled one session and sessions are file based by default. The session file is shared resource for processes which means you can only make one call to PHP at a time for one user.
在您的情况下,默认情况下,一个用户处理一个会话,而会话基于文件。会话文件是进程的共享资源,这意味着您一次只能为一个用户调用一次PHP。
Multiple user can invoke any number of processes at once depending on your systems capabilities.
多个用户可以一次调用任意数量的进程,具体取决于您的系统功能。
#1
20
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.
Laravel不直接处理请求,这是由您的Web服务器和PHP管理的。 Laravel收到您的网络服务器已经处理过的请求,因为它只是一个用PHP编写的工具,它处理与请求调用相关的数据。因此,只要您的Web服务器知道如何执行PHP并调用正确的index.php文件,Laravel就会被启动并处理它从Web服务器接收的请求数据。
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.
因此,如果您的Web服务器能够接收2个不同的调用(通常它们会执行数百个调用),它将尝试实例化2个PHP(子)进程,并且您应该在内存中并行运行2个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.
因此,如果您有依赖于其他代码的代码,这些代码可能需要很长时间才能执行,您需要在Laravel应用程序中自行处理。
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.
我们通常做的只是将数据添加到数据库,然后从使用数据存储区中的数据完成的计算中获得结果。因此,数据到达数据存储区的顺序无关紧要,首先进入数据存储区,最终结果始终相同。如果你不能依赖这种方法,你必须准备你的应用程序来处理它。
#2
2
Everything in PHP starts as a separate process. These processes are independent form each other until some shared resource comes in Picture.
PHP中的所有内容都作为一个单独的进程启动。这些进程彼此独立,直到某些共享资源出现在Picture中。
In your case one user is handled one session and sessions are file based by default. The session file is shared resource for processes which means you can only make one call to PHP at a time for one user.
在您的情况下,默认情况下,一个用户处理一个会话,而会话基于文件。会话文件是进程的共享资源,这意味着您一次只能为一个用户调用一次PHP。
Multiple user can invoke any number of processes at once depending on your systems capabilities.
多个用户可以一次调用任意数量的进程,具体取决于您的系统功能。