Page 1 of 1
Can We Pre-Compile PHP Files
Posted: Fri Dec 16, 2005 11:43 pm
by BlindMan
I'm using PHP simplify the creation of HTML pages and enforce consistency. The content of the pages is effectively static. It would be nice to 'compile' all of my PHP pages into the resulting HTML pages in order to alleviate processing on the server.
Is this a common practice?
Is there an easy way to do this?
Does the PHP server have sufficent caching to ignore this?
Re: Can We Pre-Compile PHP Files
Posted: Sat Dec 17, 2005 12:20 am
by BDKR
BlindMan wrote:
I'm using PHP simplify the creation of HTML pages and enforce consistency. The content of the pages is effectively static. It would be nice to 'compile' all of my PHP pages into the resulting HTML pages in order to alleviate processing on the server.
Is this a common practice?
Is there an easy way to do this?
Does the PHP server have sufficent caching to ignore this?
1) Yes, it's common practice.
2) Yes, there is an easy way to do this.
3) I'm not really sure there is such a thing as a PHP server in the way you're thinking of it.
LOL...
Anyway, we're going to ignore 3 and look at 1 and 2.
It's a very common practice for dynamic sites to serve large portions in a static manner. The site that I administer does it too. Makes a ton of sense when you get right down to it. The easiest way is to store a copy of the output someplace (like the /tmp directory if you have your own server) then attempt to use it each time the page is requested. If it's not there, then you dynamically generate the content and store a copy again. If it was there, then just use it and skip the dynamic generation.
It's really simple. Sprinkle in a little output buffering and file saving and you're off to the races. Google "php caching" (as an example). I'm sure you'll find an article that goes a bit more in depth.
Cheers,
BDKR
Posted: Sat Dec 17, 2005 5:23 am
by BlindMan
Thanks! I didn't realize it would be something that we would just code.