PinguLaughter Posted June 8, 2013 Share Posted June 8, 2013 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> '; } Quote Link to comment Share on other sites More sharing options...
requinix Posted June 9, 2013 Share Posted June 9, 2013 Use an array instead of lots of variables. found a mirror = false for each $mirror in your list of mirrors { check response if okay { found a mirror = true show $mirror } } if it did not find a mirror { do something } Quote Link to comment Share on other sites More sharing options...
kicken Posted June 9, 2013 Share Posted June 9, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.