What to know to understand the behavior of PHP code?
1) PHP code runs in the server side machine by the web server invoking the PHP interpreter, which will translate PHP code to HTML code.
2) The web server (for example Apache) is the program that interface with the PHP interpreter. See the following details:
2-1) first, the a web client send an HTTP request for a .php file to the web server,
2-2) next, the web server will get the .php file and pass it to the PHP interpreter
2-3) then, the PHP interpreter then translate the PHP code to HTML code,
2-4) last, the web server will pack the HTML code in an HTTP response and send it to the web client.
Reference:
http://letsdophp.blogspot.com/p/architecture-diagram-of-php-based-web.html