942Part VCase StudiesFinally, take a (Web hosting comparison) look at browser
942Part VCase StudiesFinally, take a look at browser latency. The best way to do this is to get on a known slowbrowser Internet Explorer 5.1 for Macintosh is supposedly the market leader in this category and actually time how long it takes from the initial request to the moment you seea complete Web page in your browser. Because a lot of this is controlled by the particularbrowser, there s not much you can do except to realize that complicated layouts featuringmassive tables, immense amounts of nonbreaking spaces, and hundreds of transparent single-pixels add to rendering time. CachingBesides the steps mentioned in the preceding section, another way you can make your sitefaster is to use caching. There are many types of caching, but the most important one for Webdevelopers is HTML caching. Many dynamic sites, such as Slashdot and Epinions, are actu- ally serving up mostly static pages that change every few minutes. Without this trick, feworganizations could afford to scale a Web site. The review page in Listing 47-4 is an interesting example, because although we re storing allthe data in a database, the only thing on the whole page that is dynamic is the CommunityRating score. The rest of the page changes only if updates are made to the database records. We could, therefore, easily write out the whole site as a series of static HTML pages with onePHP function embedded in the middle. You re probably thinking, That s nuts! I just went to all that work to turn my static HTML siteinto a dynamic, database-driven one and now you re telling me to go back to staticHTML?!?! But if you think about it, you see a vast difference between a static site that youmaintain by hand and a dynamic site that happens to update itself automatically whenever ameaningful change occurs. This scheme gives you the best of both worlds: the speed and scal- ability of static HTML plus the flexibility and maintainability of a database-driven PHP site. We ve written another code listing that takes all the entries in your database and writes themout to static HTML files. In the middle is a PHP snippet that includes a text file. This text filecontains the Community Rating and is updated by a separate process every hour. You candownload the code for this listing at www.troutworks.com/phpbook/. If you want to make the Community Rating call on this page fully dynamic, instead of takingcached data from a flat file, you can do that too. But you will no longer be able to constructthe entire page as a single heredoc block. The code to accomplish a static page with adynamic code block is available at www.troutworks.com/phpbook/. The code to insert a dynamic PHP block into a static HTML page doesn t look as pretty asaplain HTML page, and you must be very careful about all the quoting and concatenating, but in the end, you have an automatically generated HTML file with chunks of PHP for thedynamic bits. You could schedule this script to run on the command line once a day via a cronjob. (You redefinitely not going to be able to use the Web server module version of PHP for this task.) Oryou could kick it off whenever you add new pages to the Web site. This has another securitybenefit: You do not need to maintain a full database in production but can merely push flatfiles periodically (perhaps via some tool such as rsync), plus maintain a small database withdata only for those fields you want to display dynamically.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.