- Mastering Symfony
- Sohail Salehi
- 468字
- 2021-07-16 11:28:58
The big picture
The request/response life cycle can be summarized in these two simple steps:
- Firstly, you send your request by entering a URL in your browser.
- 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:

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 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:

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 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.
- 兩周自制腳本語(yǔ)言
- Oracle 12c中文版數(shù)據(jù)庫(kù)管理、應(yīng)用與開(kāi)發(fā)實(shí)踐教程 (清華電腦學(xué)堂)
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- Yocto for Raspberry Pi
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- Python深度學(xué)習(xí):模型、方法與實(shí)現(xiàn)
- Node學(xué)習(xí)指南(第2版)
- 編程改變生活:用Python提升你的能力(進(jìn)階篇·微課視頻版)
- SSH框架企業(yè)級(jí)應(yīng)用實(shí)戰(zhàn)
- WCF技術(shù)剖析(卷1)
- ASP.NET jQuery Cookbook(Second Edition)
- Programming MapReduce with Scalding
- Java程序設(shè)計(jì)項(xiàng)目教程(第二版)
- 大數(shù)據(jù)高并發(fā)Redis一本通
- JavaScript語(yǔ)言精髓與編程實(shí)踐