The web server will generally decide what to do with the file based on its "extension" (i.e. the last part of the file name); there are lots of variations that are possible, but the common default configuration would be:
- File names ending
.html
will be read directly by the web server, and sent back to the browser with a Content-Type
of text/html
, regardless of their content.
- File names ending
.php
will trigger execution of a PHP interpreter, as a module, a CGI script, or a FastCGI proxy. The PHP interpreter will then read the file, send a Content-Type
of text/html
by default, and output any file content not between <?php
(or <?=
) and ?>
directly as though told to echo
it.
If you have a fully-trusted HTML page with no instances of <?
inside, the only difference will be a small performance advantage in the web server reading it rather than passing control to a PHP interpreter. The exact overhead depends on exactly how it's running - CGI mode is very slow, but rarely used; a modern configuration with FastCGI and OpCache would add very little delay.
The only other difference would be if someone could edit the HTML file and accidentally or maliciously include code that would be interpreted by PHP. By saving it as .html
, and checking your server configuration, you can be sure that this code will not execute.
Note that these kinds of small differences are sometimes referred to as "micro-optimisations", and the general advice is to only look at them when you've exhausted all other optimisations, and to only optimise based on real benchmarks of your application. Even if millions of people request this page, each of them might only see a few milliseconds improvement from this change, and your server would see a tiny fractional reduction in CPU usage. But a single database query might be taking hundreds of times that, and implementing a more efficient query, or an effective cache, would give you far more of a performance boost.
If you find that these files really are causing a measurable delay, you should instead commit more effort to finding the best solution, rather than only making a small change. Since these are static files, you could look at using a separate CDN (e.g. CloudFlare, Akamai) or hosting them on a separate server tuned specifically to serve these files, and not fighting for resources with your dynamic content.