Go Back   Winamp Forums > Community Center > General Discussions

Reply
Thread Tools Search this Thread Display Modes
Old 5th April 2004, 14:41   #1
Emok
Senior Member
 
Join Date: Sep 2003
Posts: 132
A Code That Will Swap Hosts

Hi evryone just wondering if any of you knows a way that if a host is down that is hosting a image for your website. The website will detect this and swap hosts of the image to another host containing the same image

any help would be gratly appriciated

Emok
Emok is offline   Reply With Quote
Old 5th April 2004, 15:15   #2
zootm
Forum King
 
zootm's Avatar
 
Join Date: Jan 2002
Location: the nether reaches of bonnie scotland
Posts: 13,378
the problem with this is that it requires you to test the host by seeing if it times out. so if you do detect that the host is down, it'll add a good 5-10 seconds to the page loading time. you'd be better off adding a link that says "alt. source" or something to the bottom.

it can be done in PHP, but i don't know how - i've seen it done (and added code to do it myself) before. but, as i say, it's not a practical thing to really do...

zootm is offline   Reply With Quote
Old 5th April 2004, 15:21   #3
griffinn
Court Jester
(Forum King)
 
griffinn's Avatar
 
Join Date: May 2000
Location: Your local toystore
Posts: 3,502
Send a message via ICQ to griffinn
Say your local website is host-a.com, and your image is mirrored as http://host-b.com/img.gif, http://host-c.com/img.gif and http://host-d.com/img.gif.

Then you can set up a script like this on host-a.com:
PHP Code:
<?
$img 
file_get_contents('http://host-b.com/img.gif')
        or 
file_get_contents('http://host-c.com/img.gif')
        or 
file_get_contents('http://host-d.com/img.gif')
        or die(
'Cannot get image');

header('Content-type: image/gif');
echo 
$img;
?>
Save this in, say, mirrored-img.php on host-a. Then your web pages can use <img src="http://host-a.com/mirrored-img.php"> to get the file from one of those three sites.

Adapt accordingly. Ideas: (1) Use GET variables to make that script grab any named mirrored file; (2) Build some intelligence into that script to discover the file type and output suitable content-type headers; (3) Randomise the order in which the mirroring hosts are contacted so you get load-balancing, sort of.

You still have to set up the mirroring yourself, of course.

The smiley slot machine! | Quotable Blog
griffinn is offline   Reply With Quote
Old 5th April 2004, 15:38   #4
Emok
Senior Member
 
Join Date: Sep 2003
Posts: 132
Cherz Evryone
Emok is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Community Center > General Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump