/    Sign up×
Community /Pin to ProfileBookmark

[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

[code=php]<?php
class ZapDataNetwork
{
// 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’;

}
}

?>[/code]

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.

Have fun & enjoy coding!

Zach [Zutery]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Zutery spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...