Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

68 users online



(Need Help With) File Functions and More

(Need Help With) File Functions and More

Currently viewing this thread: 1 (0 members and 1 guests)


Page 2 out of 3
Phil

Phil

with Mr. Jones
Status: Offline!
PHP:

<?php

# page.php
if( filemtime("/path/to/directory/.") <= filemtime('cache.csx') ) {
     
$files unserialize(file_get_contents('cache.csx'));
} else {
     
# old/bad cache
     
echo('Rewriting Cache!');
     
# read dir
     
$handle opendir('dirname');    
     while(
false !== ($File readdir($Handle))){
        
$fileArray[] = $File;
     }     
     
# store serialize() dir in cache.csx
     
$h fopen($filename'w+')
       
fwrite($hserialize($fileArray));
     
# set files array to $files
     
$files $fileArray;
}
# now you have dirlist stored in $files
foreach($files as $file) {
    print 
$file;
}

?>

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

Last edited by Phil, July 29th, 2003 10:51 PM (Edited 1 times)

BigToach

BigToach

Neversidian
Status: Offline!

well if you use a php upload script you can just an element to the serialized array when you upload it. or you could have it run once a day with a date('dmy') as the time. if the current day doesnt match the stored day scan the directory.

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

Adam

Adam

Status: Offline!

Ares, you just create a cache file by writing to cache.csx?

___________________


Current Project: LivermoreMuscle.com
Sig Hosted by Motorspin

Phil

Phil

with Mr. Jones
Status: Offline!

If its on w+, yeah, it'll create it if it doesnt exist. It might cause errors the first time - i dont now how filemtime handles nonexistant files.

as for the cache file... its basically a text file with a serialized array written it it. I just put a cool extension on it to help it stand out among other files - personal preference; it would work as .txt, .php etc

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

Adam

Adam

Status: Offline!

i though were actually CACHING someting, no just writing some junk to a file.

___________________


Current Project: LivermoreMuscle.com
Sig Hosted by Motorspin

Phil

Phil

with Mr. Jones
Status: Offline!

no, this is fake caching. I dont know how to do real caching; do you have any links?

you could also put it in database

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

Dan1

Dan1

TF Retiree
Status: Offline!

Nah I have bad luck with databases. *goes off to try the code*

Jeb

Jeb

Status: Offline!

Would someone like to outline the difference between "fake" and "real" caching for me?

If you're preventing the server from executing unnecessary code on script execution by retrieving pre-calculated values, are you not using the principle of caching?

___________________

Adam Goossens -- PHP is my mother tounge.

Linux: ( kernel.org | winehq ) -- f33l the p0w3r.

Nobody replying to your questions? Getting flamed? Getting told to RTFM? Ask your questions the right way.

Last edited by Jeb, July 30th, 2003 05:34 AM (Edited 1 times)

Phil

Phil

with Mr. Jones
Status: Offline!

Jeb... I was thinking about this in the shower. Caching means its actually stored on the users machine - thats REAL caching. I figure you could do this with a PHP script by storing when you alst added info and then mess around with last-modified headers, but I havent tried it.

I use 'fake caching' to take the load off the database or the the processer. It could be storing arrays that don't change often in a text file, or storing templates in files vs database...

thats my take on it.

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

Jeb

Jeb

Status: Offline!

Mmm hmm....

I don't think there is a real and fake caching. To cache something is to buffer data so that it can be accessed quicker than normal at a later time, and be periodically updated to reflect any changes to the source data.

But maybe I've misunderstood the definition....

___________________

Adam Goossens -- PHP is my mother tounge.

Linux: ( kernel.org | winehq ) -- f33l the p0w3r.

Nobody replying to your questions? Getting flamed? Getting told to RTFM? Ask your questions the right way.

Last edited by Jeb, July 31st, 2003 11:23 AM (Edited 1 times)

Page 2 out of 3
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0093 seconds.