Re: how to possibly cache something and the theory of better performance / better speed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




I used to use a script to grab a random image from a folder of images by
scanning the folder, returning the list of images, getting one of them
randomly and displaying it.

Isn't that what the code is doing? Maybe I'm missing something but you've only mentioned one method.

What's the second method to compare against?

OK now, getting greedy I want to take it to another level.  Instead of
having to read the folder for images every time, why not read the image
names into a file so that we can maintain therbey caching the list.  This is
based on 25-30 images in the folder you might even have more.  Since in this
case we're not going to add images too often, then we can upload the images
delete the cache list and a new one will be generated hopefully saving time
for all future executions.


Assuming only 25-30 images am I splitting hairs here?

Yes. I don't think you'll notice any difference with this number, though a quick script would tell you for certain.

$orig_image = 'logo.jpg';
$cache_folder = '/path/to/folder';
for ($i = 0; $i < 500; $i++) {
  copy($cache_folder.'/'.$orig_image, $cache_folder . '/' . $i . '.jpg');
}


Of course if I have 200 pictures, then this is the way to go but would this
really make a difference?

Once you get a lot of images (500? 1000? more?) it will but if you only expect 30 there's not much point.

Using a cache file you'll need extra checks (make sure nobody slips in a symlink to /etc/passwd or a url or something) - but you should be doing those checks anyway.

--
Postgresql & php tutorials
http://www.designmagick.com/

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux