How Web Applications Work

Mike Sparr
2 min readDec 12, 2018

--

Occasionally I get asked to answer questions on Quora and other networks, and often there are questions asking why someone cannot read a website’s PHP or [insert scripting or server language here] source code. The simple answer is that what is sent back to your computer or device’s browser is usually just HTML content that the browser reads (or some other format of data like JSON, XML, etc.). To help explain how a web application is assembled, I prepared the following in hopes it helps others better understand what is happening.

  1. Your device or computer is connected to the Internet and your browser requests a URL (yahoo.com/finance.php)
  2. Your device connects to the public Internet via your ISP (broadband or cellular provider) and tries to find the address for yahoo.com via DNS lookup which is like a phone book for network addresses to computers connected to the Internet. It allows a look up by [domain] name and returns an IP address like 55.55.55.55, just like your name might return your phone number in a phone book. This is the network address of the computer that is hosting that domain.
  3. Your request is transmitted through the Internet to the IP address you found similar to typing that number in your phone and placing a call.
  4. The computer connected to that IP address would have web server software running on it that will go fetch the requested file, and send it back. (a) if just a .html file, the server finds it on the computer and sends it back. (b) if a .php file, the web server knows to hand off the request to the application server that will process the PHP code.
  5. The application server receives an HTTP Request from the web server, finds the file with the source code (programming instructions) for that web address (i.e. finance.php), and executes your PHP program.
  6. The program references a connection to a database server (just another program run on the computer) and sends it a “query” to request data stored and organized by the database server.
  7. The database server fetches the files requested from the query.
  8. The database server sends back the requested data to the application server.
  9. The application server combines this data with any other data your program instructs it to add, and sends it all back to the web server as an HTTP Response. Typically you just output HTML-formatted text but your program can inject data into it as it loops, etc.
  10. The web server sends back the HTML text to the requesting connection.
  11. The data is transmitted over the Internet back to your computer or device and the connection ends.
  12. Your device browser reads the HTML code (that was generated) and displays it on the screen.

--

--