PDA

View Full Version : Tutorial: Real time bandwidth-based redirection (PHP)


ask
12-01-2002, 07:41 PM
Posted this on another forum a while ago, so i figure why not here as well:

---

For you advanced users this might turn out to be useful. For example a good application of this would be if you host your site at college, and the tech deparment gets pissed if your using a lot of bandwidth. So you can mirror to your girlfriends computer, and use her bandwidth and so forth.

Its really inexpensive, and useful. I used it when I had a file server in Berkerly.


<?

$server = "127.0.0.1"; // Your server.
$maxband = "500000"; // Maximum Bandwidth before rollover in bytes.
$mirror = "mirror.yoursite.com"; // The mirror server.

$handle = fopen ("http://$server/server-status?auto", "r");
while (!feof($handle)) {
$buffer=fread($handle,4096);
}
fclose($handle);

list($th,$tb,$cpu,$uptime,$rs,$bs,$br,$busy,$idle, $scoreboard)= split ("\n", $buffer);


$bs = ereg_replace(".*BytesPerSec: ", "", $bs);

if ($bs > $maxband) {
$location = "http://$mirror/$file";
} else {
$location = "http://$server/$file";
}

echo "<p>$server limit is $maxband bytes. Current bandwidth is $bs.</p>";
echo "<p>Sending you to <b>$location</b>.</p>";
?>

h88
12-04-2002, 08:33 PM
Did'nt try combining these commands b4, Thanx for sharing it here m8. :)

pom
12-05-2002, 05:00 AM
:o :o :o

h88
12-05-2002, 05:01 AM
Something wrong Senior Member. :q:

pom
12-08-2002, 09:35 AM
No no, I just swallowed my tongue.

:crazy: :crazy: :crazy: