Which is more efficient/faster when calling a cached image?
Posted
by andufo
on Stack Overflow
See other posts from Stack Overflow
or by andufo
Published on 2010-05-13T15:44:23Z
Indexed on
2010/05/13
16:34 UTC
Read the original article
Hit count: 247
Hi, i made an image resizer in php. When an image is resized, it caches a new jpg file with the new dimensions. Next time you call the exact img.php?file=hello.jpg&size=400 it checks if the new jpg has already been created.
- If it has NOT been created yet, it creates the file and then prints the output (cool).
- If it ALREADY exists, no new file needs to be generated and instead, it just calls the already cached file.
My question is regarding the second scenario. Which of these is faster?
- redirecting:
header('Location: cache/hello_400.jpg');die();
- grabbing data and printing the cached file:
$data = file_get_contents('cache/hello_400.jpg'); header('Content-type: '.$mime); header('Content-Length: '.strlen($data)); echo $data;
Any other ways to improve this?
© Stack Overflow or respective owner