[REL] ZapCDN Class
Finished working on my class to serve static content to users using 3 different servers, so here's the script, for those who will know how to implement it xD
Summery: Basically what this does is you can use several different hosts, for one thing. This optimizes your server for a faster experience for your users/clients
Basically all this does is randomise the webserver that the user gets to get the content. If you go to zap you will get a random between cdn1 or cdn2 or cdn3 to serve images and SWFs to load balance.
// Function to check if a cdn is offline. Use IP or http:// method for fsockopen as $link.
public function CDNOnline($link)
if(@fsockopen($link, 80, $errno, $errstr, 1)) // Check if the connection fails
return true; // Connection suceeded
return false; // Connection failed
// Function to serve a CDN to each user
public function AssignCDN()
$this->cdn['1'] = ""; // Force Hotel & Open Habbo CDN
$this->cdn['2'] = ""; // Habless Hotel CDN
$this->cdn['3'] = ""; // Zap Hotel CDN
$this->result = rand(1, 3);
// Lets check if the servers are online, and assign a server for users as they show up.
if($this->result == '1' && !$this->CDNOnline($this->cdn['1']))
$this->result = '2';
else if($this->result == '2' && !$this->CDNOnline($this->cdn['2']))
$this->result = '3';
else if($this->result == '3' && !$this->CDNOnline($this->cdn['3']))
$this->result = '1';
// Return the CDN for the user
return 'cdn' . $this->result . '.zaphotel.net';
Have fun & enjoy coding!