Web Hosting Talk







View Full Version : Random Mirror Script


Wilcox
04-05-2007, 12:32 PM
Hello,

I am wanting to create a PHP Script that selects from a list of random mirrors for load balancing.

The ideal script would be named download.php and would be the only file that I need. I do not want to include other files. The way I want it to work is for somone to go to mydomain.com/download.php?=public/download.iso

So it would need to have a list of mirrors and like ftp.sub.domain.com/public and others that it selects from and then appends the filename that is in the url of the download.php script.

I am going to use this for a Linux site that I am currently setting up to download ISO's.

Because earch of the mirrors domain names and where they store them are different but the actual file name is the same I believe this will work.

If there is anyone willing to help me with this I would be eternally grateful!

Regards,

Brett

Xeentech
04-05-2007, 04:15 PM
just select the mirror from a table or mirrors since I guess there must already be a db of these files..?


SELECT mirror FROM mirrors LIMIT 1 ORDER BY RAND()


If you don't know about programing PHP then I'd suggested having a look at those script archive sites.

Renard Fin
04-05-2007, 06:02 PM
Hum he would like to do load balancing. I will not include code, it would be kinda long but I have an idea of how to do it:

1st- make a cronjob to check each server on a page.php file which simply do :
system('uptime', $output);
echo $output;

2nd- parse these values to see the current load of the server

3rd- load it in a DB

4th- when the user request a download, check the least used server and redirect him to it header("location: http://mirror/file.zip");

I think that would be the best way to do it.