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: 223

Filed under:
|

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.

  1. If it has NOT been created yet, it creates the file and then prints the output (cool).
  2. 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?

  1. redirecting: header('Location: cache/hello_400.jpg');die();
  2. 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

Related posts about php

Related posts about gd