LF-DevJourney
LF-DevJourney

Reputation: 28529

How does web server process the requests?

I use php and laravel as my web service.

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

  1. requests to different controllers from many users;
  2. requests to the same controller from the same user.

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

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.

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

Upvotes: 18

Views: 2854

Answers (2)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

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.

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.

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.

enter image description here

Upvotes: 24

anwerj
anwerj

Reputation: 2488

Everything in PHP starts as a separate process. These processes are independent form each other until some shared resource comes in 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.

Multiple user can invoke any number of processes at once depending on your systems capabilities.

Upvotes: 3

Related Questions