The life cycle among the Browser, Apache and PHP

I realized that, when the client enters the address in their browser, the HTTP Request massage is sent to the web server by the browser. The web server receives the HTTP Request, read it and finds the requested file, finally.

When the suffix of the requested file is .php, the web server opens it on the RAM and then refers it to the PHP Interpreter. The file is read by the PHP Interpreter line by line, and those lines which are out of the <?php ?> block, are ignored as the output by the interpreter(is it right?), and those that are in the PHP block are interpreted line by line. If I am right here, so I continue the debate by citing some examples.

We suppose that the browser locates these codes in the requested file: index.php

Example Html Code
    echo 'this is a test.';
    // another php codes

The PHP Interpreter doesn’t compile the first line, because it is not in the PHP block, but, since there is an Html tag so the PHP Interpreter considers the adaptable header automatically and puts the first in the output, however, insomuch that the file interpretation is not complete, so the header and the output have not been sent to the web server, yet. Is it right?

Then, the next line is compiled by the interpreter.
the next line locates in the PHP block, so it is compiled by the interpreter and it puts the text that should be echo in the continuance of the previous output. Consequently, other codes are interpreted similarly and when the index.php file is compiled completely, the interpreter sends the header and outputs into the web server.
they are send in the form of an HTTP Response to the web browser by the web server, as well.

1. Is this conclusion true for the cycle among the browser, web server and the PHP Interpreter?

2. How much request and response is formed between the browser and the web server?
3. And how much request and response is formed between the web server and the PHP Interpreter?

4. Is the file opened on the RAM by the web server or the PHP Interpreter?

5. When the interpreter considers the header, is it sent to the web server immediately or is the whole interpretation of the page sent when it was completed?

6. When the PHP Interpreter meet the first Html tag or some commands such as echo and such like, does it send the output immediately or does it send all outputs outright with the header after the page is interpreted completely?

1 Like

Wrong. Wrongwrongwrong. The browser and PHP don’t mix.

  1. No. The browser requests a resource (no matter the type) via HTTP from the server and the server (again via HTTP) delivers that resource. Then the browser starts parsing the received text as good as possible (which is an amazing thing given all the (HTML-wise) crap out there). How the server builds that response is the responsibility of the server alone.

  2. One request, one response for each resource (HTML may contain resources such as CSS and JS files, which are not known until the HTML is actually parsed).

  3. None in the sense of HTTP. One otherwise. But eventually it depends on the web server’s programming.

  4. By PHP. The hand-off to PHP is usually decided upon file-type rules in the web server’s configuration.

  5. PHP is synchronous, so it sends anything immediately to the web server (unless you have caching active)

  6. That depends on various settings.

1 Like

Does php read the file even if it has static content with .php suffix?

I don’t understand, Does php return the header and outputs to web server when the dynamic file is interpreted completely?

PHP reads every file it is handed by the web server, no matter what it is. The decision what to hand over does not lie within PHP at all.

See 5. and 6.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.