Reply
image cache-ing
Old 08-17-2004, 08:35 AM image cache-ing
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Sorry people I have put this thread in the wrong Forum, Feel free to move it if you like admin.

This is in reference to polls.

I dont want the image (dynamic via GD) to be created each time its requested. I am after cacheing via $_SESSION vars so that they just get to view the same image for a specific period of time.

So before I jump straight in I though I woulod seek the infinate wisdom of this forum and get some good direction.

Cheers Ibbo

Last edited by ibbo : 08-17-2004 at 08:36 AM. Reason: Wrong Forum
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
When You Register, These Ads Go Away!
Old 08-18-2004, 07:24 AM Solution
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
PHP Code:
 // stage 1, poll the image cach dir for out of date images.
// set at 5 mins
$path IMAGEDIR .'/imgcache/';
$state false;
        
if (
is_dir($path) ) {
  
$handle=opendir($path);
   while (
false!==($file readdir($handle))) {
     if (
$file != "." && $file != "..") { 
          
$diff = (time() - filectime("$path/$file"))/60;
          
// file 5 mins old or older
          // remove file set flag 
            
if ($diff 5){
               
unlink("$path/$file");
              
$state=true;
            }
       }
    }
    
closedir($handle);
}
// flag set old image had gone
// create new.

if($state){      
 
imagepng($imIMAGEDIR .'/imgcache/'.$sessionid.'.png');
}
// no image exists
// create new.
if(!file_exists(IMAGEDIR .'/imgcache/'.$sessionid.'.png')){
 
imagepng($imIMAGEDIR .'/imgcache/'.$sessionid.'.png');

Of course I use a temple so I assign the sessionid to a variable that my template will parse and display depending on your session id.

Yes sesions are required for this to work along with the filectime function.

Hope this helps anyone else who needs this, bit of a poor response.

Ibbo
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Reply     « Reply to image cache-ing
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11899 seconds with 12 queries