Raised This Month: $ Target: $400
 0% 

[SNIPPET] Multiple Fast Download URLs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
D-Skript
BANNED
Join Date: Apr 2010
Location: 127.0.0.1
Old 04-17-2010 , 20:40   Re: [SNIPPET] Multiple Fast Download URLs
Reply With Quote #1

Interesting indeed.
D-Skript is offline
KawMAN
SourceMod Donor
Join Date: Sep 2007
Location: Cracov
Old 04-25-2010 , 08:56   Re: [SNIPPET] Multiple Fast Download URLs
Reply With Quote #2

I have made similar script
Feature:
- Switching mirror every download request (simple bandwidth balancer)
- Checking if file exist on mirror and if not, checking another mirror. If file cant be found on any mirror sends to client "404 Not Found".
PHP Code:
<?
//Written by KawMAN
ini_set('display_errors''1');
//set_time_limit  ("10"); //Optional timeout
$mirrors = array();

//Mirrors here
$mirrors[] = "http://mirror1.wsciekle.pl/cstrike";
$mirrors[] = "http://mirror2.wsciekle.pl/fd";
$mirrors[] = "http://mirror3.wsciekle.pl/cstrike";


$mircount count($mirrors);

$fn=$_GET["fn"]; //Filename

// Get first mirror to check
$clnr GetNextMir();
if(
$clnr == -1) exit("cant read from fd_redir_c.txt");
//Change 'first mirror' to next mirror on list
if($clnr>=$mircount-1) {
    
SetNextMir(0);
} else {
    
SetNextMir($clnr+1);
}

$loop=0;
while(!
redir($clnr)) {
    if(
$clnr>=$mircount-1) {
        
$clnr=0;
    } else {
        
$clnr++;
    }
    if(
$loop>$mircount) { //When all mirrors return Not Found, script return Not Found
        
header("HTTP/1.0 404 Not Found");
        exit(
'Not Found');
    }
    
$loop++;
}

function 
GetNextMir() {
    
$uchwyt=fopen("fd_redir_c.txt""r");
    if (
$uchwyt === false) {
        return -
1;
    }
    
$fdc fread($uchwytfilesize("fd_redir_c.txt"));
    
fclose($uchwyt);
    return (int)
$fdc;
}
function 
SetNextMir($clnr) {
    
$uchwyt=fopen("fd_redir_c.txt""w");
    
fwrite($uchwyt$clnr);
    
fclose($uchwyt);
}
function 
redir($nr)
{
    global 
$fn$mirrors;
    
$uchwyt = @fopen($mirrors[$nr].$fn,"r");
    if (
$uchwyt === false
    {
        return 
false;
    }
    else
    {
        
header("location: ".$mirrors[$nr].$fn);
        return 
true;
    }
}
?>
in folder with that script must be file called fd_redir_c.txt with chmod 777
now sv_downloadurl should looks like this:
sv_downloadurl "http://main.wsciekle.pl/fd_redir.php?fn="

also you can create folder for example "fastdownload" and put to it file .htaccess with something like this:
PHP Code:
RewriteEngine On
RewriteRule 
^(.*) http://main.wsciekle.pl/fd_redir.php?fn=/$1 [R,NC] 
and now sv_downloadurl can looks like :
sv_downloadurl "http://main.wsciekle.pl/fastdownload"

Working example:
http://fastdownload.wsciekle.pl/maps...ood_rm.bsp.bz2 download, check source, download, check source
__________________

Last edited by KawMAN; 04-25-2010 at 09:17.
KawMAN is offline
Send a message via ICQ to KawMAN Send a message via Skype™ to KawMAN
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode