I used php on my website so it can display multiple languages. I noticed the size of the html files reduced because most of the text was moved to a new large php file, which contains all "idiomatic" text in all languages available (just two in my case).
My problem is: Previously a html page was downloaded with just the necessary text. Now a smaller html page is downloaded but a large php file is always included, whether the html uses more or less lines of it.
Questions:
include_once(file.php);
or require_once(file.php);
) what is happening? Is the content of the file.php
being copied to the html? Is it just used to say to the language processor "If you need to resolve a name, you may want to look at file.php
"?P.S: Anyone tried PHP Speedy? Does it really works? Does it have any problems (compatibility) ?
I found out:
1) Every include / require statement is replaced by the content of the included / required file. The content of the included file itself is becoming part of the executing script however if it will become part of the HTML response depends upon the content itself.
2) Unless you have a very large number of visitors you will hardly notice a difference between including one large file and several smaller ones. However its good practice to include only parts which are actually required because that way you are saving web server memory and resources which might present a problem in case of a large number of requests.
3) It doesn't really matter where you include your code. For pure organization reasons its good to include all the stuff right at the beginning of the script however sometimes this is not possible which means that you'll often see code included inside functions etc.
4) There is some latency involved with parsing PHP files when compared against pure HTML files because the process involves a "roundtrip" to the web server extension itself however because of the internal caching mechanisms etc. that latency is very hard to spot, if not almost impossible to prove statistically.
EDIT: If you are concerned about your web site performance a good place to start are some of the Google Chrome extensions such as Page Speed and Speed Tracer. They will help you pinpoint the usual problems that might lower your web site performance.
For the server side its always good to use code profilers to find potential performance hogs such as high number of function calls etc. For that you can use xDebug PHP debugger which comes with an excellent profiler and WebGrind to analyze the performance itself.