Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases
You last visited: Today at 13:50

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Release - Load Balancer PHP Basis

Discussion on Release - Load Balancer PHP Basis within the Coding Releases forum part of the Coders Den category.

Reply
 
Old   #1
 
JPGaming's Avatar
 
elite*gold: 169
Join Date: Jul 2011
Posts: 392
Received Thanks: 261
Release - Load Balancer PHP Basis

Musste gerade lachen, weil ich ein älteres (jedoch funktionierendes) Script für einen Load Balancer auf PHP Basis gefunden habe. Dies verwende ich nicht mehr, da es nicht ganz das gelbe vom Ei ist. Vielleicht hat der ein oder andere dafür Verwendung?! Ich denke, der Quellcode ist recht selbsterklärend, sollten jedoch Fragen entstehen tut euch keinen Zwang an.

Klasse selber
PHP Code:
<?php defined('SYSPATH') or die('No direct script access.');
class 
Loadbalancer
{
        
/*Holds counter for active load balacer*/
        
public $balancer_counter null;
        
/*Current base url*/
        
public $balance_base_url null;
        
/*Array for later getting online balancer*/
        
public $balancers_online = array();
        
/*Array for later getting offline balancer*/
        
public $balancers_offline = array();
        
/*Holds the pre before url base, s = default*/
        
public $pre_url 's';
                
        public function 
return_current($advanced_mode false)
        {
            if(!
is_null($this->balancer_counter) && !is_null($this->balance_base_url)) {
                for(
$i 1$i < ($this->balancer_counter+1); $i++) {
                    
$call_url $this->pre_url.$i.'.'.$this->balance_base_url;
                    try {
                        
fsockopen($call_url80$errno$errstr30);
                        
array_push($this->balancers_online$call_url);
                    } catch(
Exception $e) {
                        
array_push($this->balancers_offline$call_url);      
                    }  
                }
            } else {
                return 
'balance_counter || balance_base_url is empty.';                
            } 
            
            
$balancing_array = array();
            
            if(
$advanced_mode === true) {
                
$dir getcwd();
                if(
file_exists($dir.'\balancing.txt')) {             
                    
$file fopen($dir.'\balancing.txt''r');
                    while(
$singlecluster fgets($file1024)) {
                        
$singlecluster str_replace(' '''$singlecluster);
                        if(empty(
$balancing_array[$singlecluster])) {
                            
$balancing_array[$singlecluster] = 1;
                        } else {
                            
$balancing_array[$singlecluster]++;
                        }
                    }
                } else {
                    
$file fopen($dir.'\balancing.txt''a');
                    for(
$i=0;$i<$this->balancer_counter;$i++) {
                        
fwrite($file, ($i+1)."\r\n");
                    }
                    
fclose($file);                        
                }
            }
            
            try{
                if(
$advanced_mode === true) {
                    
$lowest['cluser'] = 99999999;
                    
$lowest['joins'] = 99999999;
                    foreach(
$balancing_array as $key => $value) {
                        if(
$value $lowest['joins']) {
                            
$lowest['cluster'] = $key;
                            
$lowest['joins'] = $value
                        }                         
                    }
                    
$random_cluster_point = (int) $lowest['cluster'];
                    
                    if(!
is_numeric($random_cluster_point)) {
                        
$random_cluster_point 1;
                    }
                    
                    
$dir getcwd();
                    
$file fopen($dir.'\balancing.txt''a');
                    
fwrite($file, ($random_cluster_point)."\r\n");
                    
fclose($file);
                } else {
                    
$random_cluster_point rand(0, (count($this->balancers_online))-1); 
                }
                return 
$this->balancers_online[$random_cluster_point-1];
            } catch (
Exception  $e) {
                return 
'No Clusterpoint online!';                
            }
        }
}
Call this per
PHP Code:
/*Calling new Loadbalancer (CLASS)*/
$loadbalancer_file = new Loadbalancer;

/*Set Loadbalancer Cluster Count*/
$loadbalancer_file->balancer_counter 3;

/*Balancer URL*/
$loadbalancer_file->balance_base_url 'change_this_url.com';

/*Balancer Pre URL*/
$loadbalancer_file->pre_url 's'// -> s1., s2., ..                         

/*Get Current Loadbalancer, PARAMETER: Advanced Mode (slower!)*/                         
$this->template->current_loadbalancer $loadbalancer_file->return_current(true); 
Mehrmals Aufruf ist möglich, sodass es auch verschiedene Balancer für bestimmte Sachen geben kann.
JPGaming is offline  
Reply


Similar Threads Similar Threads
[S]Balancer für Browsergame [B]E*Gold
04/06/2012 - elite*gold Trading - 0 Replies
Hallo, Ich suche jemanden der mir hilft mein Browsergame Mafiauntergrund auszubalancieren. D.H. herrausfinden was man zu schnell schaft wie man das am besten anpassen könnte etc. wer Interesse hat soll mich in Skype adden heiße dort wie hier, oder einfach in den Thread posten. Schlagt mir einfach vor was ihr haben wollt.
Release New SmartzWHZ + Lock N Load ISO Wallhack [RELEASE FREE]!!‎
10/07/2011 - Soldier Front Hacks, Bots, Cheats & Exploits - 5 Replies
F U WANT THAT CHEAT JUST ADD ME IN FACEBOOK ---------=tHe SeCrEt GM !!
Release New Method of [Lock N Load + SmartzWHZ Wallhack] RELEASE FREE!!
09/22/2011 - Soldier Front Philippines - 12 Replies
#removed



All times are GMT +2. The time now is 13:50.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.