The attached text file contains a script that I've gotten from a web site and that I've been using for a while now to generate on the fly PNG headers. There can be several headers on one page, spanning several days worth of articles. The script works, except it's a huge overhead because it generates each header every time it gets displayed. What I'd like to do is amend the script to where it will creates a physical PNG file on the server, so that the next time it's called, it will check its "cache" first to see if that particular header already exists before creating another. Basically something to the tune of:


a web page calls the script:

   script checks internal cache for that header
     if header doesn't exist
       create header -> save in cache (disk based?)
     endif
     serve header from cache
   end routine

I don't know if it makes sense to incorporate this with an MySQL database which contains pointers to the physical files on disk. I don't know if that will speed up the searching for a particular header (searching the DB, as opposed to scanning the disk directory.) The only thing I can think of is to have a database with a table that contains both article dates as well as the pointer, so the search only has to go through a small set of records, as opposed to the whole DB, but is it really worth it?

Now, somewhere in there, it also needs to scan the cache for old headers that are no longer needed, based on a time frame that I set (maybe 14 days? maybe 30 days? I haven't decided yet.) Again, maybe using a DB is worth it so one can simply delete all the pointers and physical files confirming to a specific range search in the DB? Right now, I just want the thing to cut down on CPU usage because it's generating those headers every time a page gets called. Not good.

--
W | I haven't lost my mind; it's backed up on tape somewhere.
 +--------------------------------------------------------------------
 Ashley M. Kirchner <mailto:[EMAIL PROTECTED]>   .   303.442.6410 x130
 IT Director / SysAdmin / WebSmith             .     800.441.3873 x130
 Photo Craft Laboratories, Inc.            .     3550 Arapahoe Ave. #6
 http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, U.S.A.

<?php
  function label($text) {
    $georgia    = $_SERVER["DOCUMENT_ROOT"]."/fonts/georgiaz.ttf";
    $freeformi  = $_SERVER["DOCUMENT_ROOT"]."/fonts/tt1002m_.ttf";
    $fontsize = 11;
    $pad = 30;
    $image = imagecreate(1000,25);
    $background = ImageColorAllocate($image, 115,180,200);
    $bcolor1 = ImageColorAllocate($image, 125,190,210);
    $bcolor2 = ImageColorAllocate($image, 105,160,180);
    $bcolor3 = ImageColorAllocate($image, 105,170,190);
    $color = ImageColorAllocate($image, 0,17,85);
    ImageRectangle($image,0,0,1000,25,$background);
    ImageTTFText($image, 30, 0, 49, 29, $bcolor1, $freeformi, strtoupper($text));
    ImageTTFText($image, 30, 0, 53, 33, $bcolor2, $freeformi, strtoupper($text));
    ImageTTFText($image, 30, 0, 51, 31, $bcolor3, $freeformi, strtoupper($text));
    ImageTTFText($image, $fontsize, 0, (int)($pad/2), 18, $color, $georgia, "::: 
".stripslashes($text));
    return($image);
  }
  Header("Content-type: image/png");
  ImagePNG(label($text));
  ImageDestroy($image);
?> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to