Jump to content

Provide multiple mirrors if a file doesn't exist


PinguLaughter

Recommended Posts

I want a Mirror script which determines whether or not a certain file is accessible or not. If the mirror1 is accessible, it will present the link to mirror 1. If mirror 1 is not accessible, it will present the link to mirror 2.


This so far is perfect, however I would like more mirrors. For example, if mirror 2 is unavailable, mirror 3 will be presented. If mirror 3 is unavailable, mirror 4 will be presented and so on. I'm just not quite sure exactly how I could make this work. Has anyone got any suggestions that would be highly appreciated. I've tried quite a lot of things already!



$mirror1 = "download1.exe";
$mirror2 = "download2.exe";
$header_response = get_headers($mirror1, 1);
if ( strpos( $header_response[0], "404" ) !== false )
{
echo '
<a href="', $mirror1, '">Download Mirror 1</a>
';
}
else
{
echo '
<a href="', $mirror2, '">Download Mirror 2</a>
';
}

Link to comment
Share on other sites

It'd be best to have a separate background script update a local DB with the status of the files on the various mirrors. Then just list any mirrors that have the file as of the last check. Doing a check of each mirror on each page load will slow down the loading of the page, especially if there are issues (such as the mirror being down).

 

Lastly, present all the mirrors that do appear to have the file, rather than just the first one. Just because a mirror is accessible to you doesn't mean it is accessible to your end user. If it doesn't work for them they need to be able to choose a different mirror. Only listing the first mirror sort of defeats the purpose of mirroring anyway, unless your doing some randomization/geo-locating of the mirrors.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.