官术网_书友最值得收藏!

The big picture

The request/response life cycle can be summarized in these two simple steps:

  1. Firstly, you send your request by entering a URL in your browser.
  2. The server then responds with a page and message (success, failure, and so on) depending on your request. End of story.

The following image shows an example of the request/response life cycle:

The big picture

A web server receives a request and passes it to an action unit for further processing. In our case, this action unit is somewhere in Symfony and is in charge of receiving requests. Depending on their type, it will fetch a resource (such as a record from the database or an image from the server's hard drive) or do something (like sending an e-mail or assembling and returning a JavaScript Object Notation (JSON) string). Finally, it renders a page based on the results and sends it back to the browser. After the job is done, this action unit marks the request and response as terminated and looks for the next request, as shown in the following diagram:

The big picture

The general request/response life cycle on a server with Symfony

Look at your /web folder in your Symfony installation from the previous chapter. You can see that there is an app_dev.php file over there. Open the file (or the app.php file if you like) and pay attention to the last four lines:

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

These lines summarize the preceding story beautifully.

You can see how it is represented in the following screenshot. These are the four steps that Symfony takes to process a request and send a response:

The big picture

Well, that's the purpose of using Symfony. It sits on the web server and makes it serve for each receiving request. The second line calls a handle() method. This method is the main reason why we are here. It might look like just one innocent method, but in fact, the handle() method is in charge of managing other units that deal with databases, JSON strings, REST and SOAP requests, processing e-mails, rendering templates, and who knows what else in the future. Note that the handle() method manages the incoming requests by finding (routing) the right controller action and getting a response from it. However, it doesn't personally do the job itself. So do not underestimate the method. It might not look like doing much, but it controls everything. It makes the server components dance on the arrival of every single request.

Let's put this information in our big picture and see how it looks:

The big picture

The handle() method facilitates the flow between the browser and server

Now we have a good template to refer to. In each of the following topics, I will update this big picture so that you can get the idea of each concept easily.

主站蜘蛛池模板: 平陆县| 怀柔区| 宁远县| 荔波县| 蓬安县| 土默特右旗| 安顺市| 中方县| 斗六市| 道真| 格尔木市| 遂川县| 安塞县| 金门县| 甘孜县| 巴里| 牡丹江市| 平谷区| 城口县| 皮山县| 淮阳县| 乡城县| 水富县| 东明县| 任丘市| 固阳县| 湟源县| 绥阳县| 香港| 简阳市| 西华县| 大安市| 健康| 常德市| 克什克腾旗| 江津市| 隆安县| 图木舒克市| 个旧市| 阿拉善右旗| 北流市|