May 5th, 2008
Data Visualizationwith Venn DiagramsIn this chapter s case study, we show one way to use PHP to com- bine MySQL databases with graphic images. We build a completesystem that starts with a database and uses the gdlibrary to producea kind of visualization of the data. The portions of the book we drawon for this are: .Part II: We use PHP to interrogate a MySQL database. .Chapter 42 (Graphics): Our end-product is an image producedwith the gdlibrary. .Chapter 27 (Mathematics): We need a bit of trigonometry as wecreate the images. Scaled Venn DiagramsThe visualization we have in mind is something like the Venn diagram. If you ve ever been in an academic setting where set intersection wasbeing discussed, then you ve probably seen these diagrams they rethe circles that may or may not have overlapping portions represent- ing intersections. We say something like the Venn diagram, because scale has no sig- nificance in a traditional Venn diagram. If you want to illustrate thefact that there are people who use both BeOS and Windows, then youmight draw two circles of equal size (representing Windows usersand BeOS users) that happen to have a region of overlap. In our ver- sion, which you might call a scaledor proportionalVenn diagram, thesizes of both circles and intersections matter; the Windows/BeOSexample would become one large circle and one much smaller circle, with an overlap area proportional to the number of people in bothsets. (To see an example of this kind of diagram, please skip ahead toFigure 48-5.) The taskThe job of our code is to start with a database, provide a way to querythat database about sets and their overlap, and then display theresults as a scaled Venn diagram, generated by using the gdlibrary. Asa sample database, we use the pseudosurvey dataset that we used inthe HTML Graphics section of Chapter 42.4848CHAPTER …In This ChapterFrom database toimageScaled Venn diagramsPlanning the displayPutting it all together …
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.
Posted in Domain | No Comments »
May 3rd, 2008
943Chapter 47Converting Static HTML SitesSummaryPHP books usually assume that you are starting a site from scratch but in the real world, another very common scenario is to upgrade an existing static site. PHP and a database canbe used to take large, messy, hard-to-maintain HTML sites and make them dynamic. Thismakes the sites much easier to maintain, because they are assembled by PHP from data in adatabase. Instead of maintaining hundreds of HTML files, you can just work on one templateand let PHP assemble the pages on-the-fly. Before you do any work, you should take the time to assess your site s strategy and map outthe goals you wish to accomplish. You should also gain a clear understanding of your site sstructure and the resources you will need to support your new design. After that, you musttest your new design, create a new database, load data from possibly disparate sources intothe database, and create PHP template pages. Finally, you should assess the performance ofyour new dynamic site and possibly take steps to improve it. …
In case you need quality webspace to host and run your web applications, try our personal web hosting services.
Posted in Domain | No Comments »
May 2nd, 2008
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.
Posted in Domain | No Comments »
May 2nd, 2008
941Chapter 47Converting Static HTML SitesPerformance and CachingAt this stage you should do some performance testing and evaluation. You want to get decentestimates of: .Server latency:How long the code takes your server to produce. .Network latency:How long it takes to get the code down the pipe to you. .Browser latency:How long it takes a browser to completely render the page. You can measure server latency by putting microtime()calls at the beginning and end ofeach page, like this: This duration should average to less than one second on every page. If it s more than one sec- ond per page load, you have an architecture problem. Subseconds of latency are achieved bymuch larger and more complicated sites than yours. Make sure that you test this on a setupsimilar to your production environment a production server can be several times fasterthan a development server, so unacceptable times in development can magically becomeacceptable in production. The reason server latency is particularly bad is that it ends up costing you money to scaleyour site. Because your code hogs processor cycles, threads, database connections, andother resources longer than it should, you need to invest more in hardware than a zippier site with similar features. The cure for this type of performance problem is to simplify yourarchitecture, particularly those features (templates, objects, message catalogs, and so on) that are known to add server latency. Network latency is (insofar as Web developers can affect it) usually a function of how largeyour page is. To test this, you need to save an HTML page and all its attendant graphic files(including ads) and note their combined size. Divide by 40 kilobytes per second (a realisticestimate of the speed of a 56K modem) for a ballpark estimate of how long your data spendson the wire. Heavy pages also cost you money, especially if you pay for metered bandwidth. Your Webservers can t take another request until they finish sending all the data from this one andthe longer it takes, the fewer available threads your Web servers have at any given time. Youcan sometimes finesse the fat-page problem temporarily by looking into transparent pagecompression Apache, for example, can gzipany file before serving it up in a way that istotally invisible to the user but in the long run you just need to make your pages lighter.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.
Posted in Domain | No Comments »
May 1st, 2008
940Part VCase StudiesListing 47-4(continued)