The most famous website Facebook was developed in PHP and still using PHP, except that they are converting the PHP code executed to C++ code for performance. They call it HiphopPHP. You might want to check about HiphopPHP on Github.
Let’s get to the point on how PHP works? Above is the slide show that i made to show you guys how PHP works.
Normal PHP Working
Normally when a user or the client machine requests a page to the web server the server responds to the request by sending the requested page to the client machine. This process is simple if it is a normal HTML page. What if the requested page is a dynamically generated page like PHP. In that case the web server again requests that particular page following these steps.
- User requests the .php webpage to the web server.
- The server identifies the page to be a PHP page and it requests the PHP script engine to parse the requested PHP code.
- The server then sends the parsed output HTML page to the client.
- Finally the HTML is parsed and shown as a webpage in the client’s browser.
Working of PHP with Database
Another case is that when a requested page needs information to be retrieved from the database. In that case the PHP script engine will do the work for us, but of-course we should write the code for connecting to the database. That process is show in the third slide of the above presentation.
For this kind of requests step 1 and 2 is same as shown above.
- The server then connects to the database with credentials provided in the PHP script.
- Query’s the database and retrieves the data from the database
- Finally the PHP parser converts the data in a HTML representation and sends it to the client’s browser.