I’m trying to determine when to provide static HTML vs. when to generate HTML as needed by PHP. By that I mean when a user requests a page, is it already waiting in HTML form or is it generated by PHP, and then sent as HTML.
More specifically, what is the best option for user public pages similar to your public pages for Facebook, Linked In or similar.
If the page is for the “content generator” it needs to be generated by PHP as the content is dynamic. The assumption or general case assumes that the user updates his data as needed or at each login.
If the page is for the “content requestor” of the user’s data the page is static…it does not change as long as the user has not logged in and changed it. Hence it would make some sense to generate a static file in HTML that is served to the the requester of the user’s data. Suppose there are 10 or so requests for the public page in between the generator’s login sessions…this would save 10 server “loads” to generate the data as they are already waiting in static form.
Please note the distinction between the user generating the content “the generator” and the user requesting a public type page – “the requester”
I would like to know if someone can validate this approach. Generating Static Files of HTML that are used in between “generator” updates. This is a validation question. Is this a valid approach?
Just about any web application that includes any dynamic information at all, even stuff like printing the day’s date at the top or filling in a copyright notice at the bottom, will use dynamically generated pages.
However that doesn’t mean that the pages are dynamically loaded on each page load. Instead, there may be some caching going on to limit the server’s workload regenerating mostly-static content. (Talking about caching the generated content on the server here, not in the browser’s cache). Templating systems like Smarty do this, and most CMS systems will have some sort of cache machinery to do this as well.
You will want to look into PHP caching mechanisms.
However, this is only necessary if your website is not scaling appropriately right now. In other words, don’t worry about caching unless your server cannot keep up with the current load.
Edit: For clarity, this kind of caching is unrelated to opcode caching, and is used instead to pre-render as HTML compute-intensive or database-intensive data. The cached file is served to clients until it is deemed to be expired, then the full page rendering must take place again, hitting the database for up to date data.