Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie, we're going to take a look at the request-response cycle in PHP. This cycle describes the way that a browser and a web server communicate to process user requests. Especially if you haven't done web development before, it can be useful to see this cycle laid out for you. To start with, we have our browser, and then we have the web server. Our browser makes a request to the web server. That's when you type in the domain of the site. So let's say that you type lynda.com, it sends a request to the lynda.com web server. In our case, that's going to be local host though.
And on that web server software needs to be there to intercept that request, and we have a HTTP Daemon called Apache that's there. And Apache see's the request and says oh, okay, I'm going to see if I have a file that will help me to respond to that request. It then goes to the file system and looks for a file. Let's call that file hello.php. Apache grabs that file and then says, okay, I see that it has .php at the end. There may be PHP here that needs processing. No problem. I will do that.
So it goes to process the PHP. In the course of doing that, it may need to go back and forth to the database a couple of times. It may need to request some information from the database, store information in the database. All sorts of things can happen as it goes back and forth between them. But, once it's done processing the PHP, there's one final step where it assembles the HTML that's going to be returned and then ships that back to the browser. And that's the response that the user seeks. So it's very important that you see this cyclical process from the browser to the web server where goes to the file system, processes the file, goes to the database as many times it needs during that process.
And then, finally, generates HTML that's sent back to the browser. There's no chance to process PHP after the HTML has been completely generated. There's no chance to do it once it's gotten to the user's browser or anything like that. It happens, only in this one spot. Where we process the PHP, after Apache goes and finds the file. This is often also referred to as the request-response cycle because we're making a request to the server and it's responding with something back to us. So, it's a request-response cycle. Now, while this may seem simple, I think it's very important for you to keep this in your head as a mental picture as we continue developing PHP. Because a lot of things we're going to learn, like header redirection, alpha buffering, setting cookies, all those kinds of things, are really going to be affected by this cycle.
So it's important to have a good firm understanding of this, right from the start.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98508 Viewers
61 Video lessons · 85800 Viewers
71 Video lessons · 69704 Viewers
56 Video lessons · 102010 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.