Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 479
LF00 Avatar asked Dec 21 '16 05:12

LF00


People also ask

How do web servers respond to requests?

The web server will respond, sending the browser the requested page, again, through HTTP. If the requested page does not exist or if something goes wrong, the web server will respond with an error message. The browser will then be able to display the webpage. Multiple domains also can be hosted on one web server.

How does a web server handle multiple requests?

The server opens a socket that 'listens' at port 80 and 'accepts' new connections from that socket. Each new connection is represented by a new socket whose local port is also port 80, but whose remote IP:port is as per the client who connected. So they don't get mixed up.

Does a web server send requests?

The messages sent by the client, usually a Web browser, are called requests and the messages sent by the server as an answer are called responses.

How does web server understand HTTP request?

It starts either manually — when you enter an URL in the address bar of your browser — or programatically — by apps, websites (JavaScript), or other programs — and ends when response is received, and between that the magic happens. This is how we typically understand an HTTP request (an oversimplified representation).


1 Answers

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

like image 70
Antonio Carlos Ribeiro Avatar answered Oct 05 '22 18:10

Antonio Carlos Ribeiro