I am trying to write a script that orders a given list of servers in order of most bandwidth free (in kb/s or mb/s) then tells the downloading client to try to connect to the servers in that order. However, I do not know what php function (if there is one built in) that I can use that will return the amount of bandwidth a remote server has free/in use.
As of now, all I have is primitive direct links to the servers, so what usually ends up happening is server 1 gets overwhelmed while server 3 sits idle, so I am trying to fix that problem. Thanks in advance for any help.
[RESOLVED] Find Bandwidth of Remote Server?
PHP alone can't possibly tell you anything about the state of a remote server's bandwidth.
I suppose the best thing you could do, if you had access to execute shell commands, is to check the latency of the remote servers by pinging them, and redirecting to the server with the lowest ping. This would probably consume a lot of resources though, not sure.
First, you might try building a list of servers and then just randomly grabbing a server from the list. That won't evenly distribute load, but it may provide enough help.
Thanks for the help. What else besides PHP would be needed to determine how much free bandwidth a remote server has? (I am trying to get something like rapidshare where it tell you the status of each server, except the script will automatically pick the server with the most free resources) The problem is, the files on the servers range from a few megabytes, to hundreds of megabytes, so randomly distribution won't always work, but pinging will probably work if I can't figure out how to find the status of the remote servers.
Bandwidth doesn't work like that. You don't have "bandwidth free". Nor is it reasonable to find it remotely.
You COULD use something like SNMP (I do not advocate running SNMP unprotected on the internet) to measure some network statistics on each of the remote hosts and pick one which has been quiet-ish recently.
Or you could add up the total amount of downloads that have been through each server recently (assuming you know the size of the file) and assuming each download completed, choose one which should be free.
But even if you could determine how much "bandwidth a remote server has", you'll have no way of knowing how congested links between the downloading computer and it are, so it's a bit of a pointless exercise.
Mark
So is your suggestion just to leave it as direct links? Because like I said, I tell people to use server 3, but for some reason, server 1 always ends up overloaded, while server 3 basically does nothing. (and server 2 is somewhere inbetween) Just as a sidenote, all 3 servers run the same configurations, it's not that server 1 has inferior specs.
Perhaps you should randomise the order which you display them in; people will probably go for the first one preferentially.
You could also consider using round-robin DNS or a randomised redirect or something.
Or perhaps you have a bigger problem - you just have insufficient overall bandwidth.
Bandwidth is generally extremely cheap, so it might be cheaper to buy a better server than try to deploy some complicated solution that may only have a limited impact on the problem.
Mark
How bout just setting up clustered servers? :p
OK thank you for all the help. I really would like to get another server, but I am barely scraping together enough donations for just those 3 servers. I think I will end up going random or round robin, or maybe just clustering them if I can find enough time to figure out how. Once again, thanks.