/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to force an browser to cache a php image?

Ok here is what I am wanting to do: Host an image on Photobucket, Use PHP to generate the image with a url as if it is being hosted on my site and cache the php generated image for faster loading later.

I am currently using a photobucket account to host my images so the original file I want to cache is actually at the following URL:

[code]http://i87.photobucket.com/albums/k126/WrestleMation/Brain_Rush_S01E01_DotNXT_DSR_XviD-E.gif[/code]

I am wanting to display the image with a URL from my site so that it doesn’t show the fact that it is on a photobucket account.

[code]http://wrestlemation.com/fa_Brain_Rush_S01E01_DotNXT_DSR_XviD-E.gif[/code]

As you can tell the image from the second link is being generated to pretty much pull in information from the first one and the displaying of the first one under the new URL works just fine.

To do what I’ve done, I used .htaccess rewriting to make the php image generation to use a standard image format url.

The php I used to generate the php image is…

[code]//Get dynamic filename from rewritten url. — which would be : Brain_Rush_S01E01_DotNXT_DSR_XviD-E
$gif_file = “http://i87.photobucket.com/albums/k126/WrestleMation/”.$_GET[‘file’].”.gif”;

//Load the image
header(“Content-Type: image/gif”);
echo readfile($gif_file);
die();[/code]

Ok so the image is generated just fine with my code but the problem is that it has to reload and redownload the image every time the browser is refreshed. Is there anyway I could force all browsers to cache the php generated image so when the generated url is called the next time it pulls from cache instead of pulling from the photobucket account?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@JunkMaleJul 04.2009 — Yeah, host the image on your hosting server. I am assuming that you are using a web hosting service which is going to be better than using a 3rd party server like photobucket.
Copy linkTweet thisAlerts:
@RottNKorpseauthorJul 04.2009 — I don't mean to sound like a jerk but that is obviously the worst response that could be given as it is so completely not helpful that you might as well just had not replied.

I appreciate any help I can get but that isn't even help.

Regardless if I hosted it on my server or not I would want to still do the generated images because it provides a way to shorten urls and make long term use urls...if I just hosted them in a folder and people used that folder but then I decided to restructure the server and move the gifs then all of the hotlinks would break where as using php generation I could move them at any time and nothing would error.

So its not about bandwidth or hosting space or whether using a 3rd party host is a good option or not. In fact if I got this working I could start on 3rd part and then move them to my server or another another server and so on without any hotlinks breaking.
Copy linkTweet thisAlerts:
@DragonkaiJul 05.2009 — How do you know it's not caching? Have you checked your own browser's cache. From what I know, browsers automatically cache and theres no specific command that forces browsers to cache. In fact you can't force browsers to do anything. However from this, there seems to be a javascript method. http://www.jguru.com/faq/view.jsp?EID=428820
Copy linkTweet thisAlerts:
@RottNKorpseauthorJul 05.2009 — thanks for the link Dragonkai...I'll look into it and yes I do know its not caching because of testing it as Firebug has a feature of showing if something is pulled from cache or not.
Copy linkTweet thisAlerts:
@MindzaiJul 05.2009 — Make sure you are setting the correct cache headers:

http://developer.yahoo.com/performance/rules.html#expires

Also double check you don't have cache disabled in Web Developer or something similar, that's caught me out before.
×

Success!

Help @RottNKorpse spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...