PHP Request-Response Cycle
This cycle in PHP describes the way that a browser and a web server communicate to process user requests. It may seem simple, but it’s important to keep it in mind while developing with PHP because things like header redirection, output buffering and setting cookies are all affected by this cycle.
- To start with, we have our browser and the web server.
- The browser makes a request to the web server, e.g. you typed in the domain of a site.
- On that web server, a software will need to intercept that request and that software is called “Apache”.
- Apache then sees the request and will search the file that corresponds to it.
- Afterwards, it then goes to the file system and looks for that file. When found, it checks if that file has a
.phpextension and if there is, the PHP code in that file will be processed.
- During the processing, Apache may need to go back and forth to the database a couple of times, it may be to request some information from the database, store information in the database, etc.
- Once the processing is done, there’s one final step in which it assembles the HTML markup that’s going to be returned and then sends that back to the browser and that’s the response that the user sees.
Previous Post: PHP Overview
Next Post: PHP Variables and Comments
This is part 2 of the PHP Basics series.