Take the 2-minute tour ×

I wish to make use of my unlimited shared hosting to create several small shared hosting accounts that I can offload processing to. So I need to create some logic in PHP to create the basics of a Load Balancer.

I have 4 shared accounts, one is the main site and the other 3 is the processing server accounts. Please see image.

I want to know how I can determine which server to pass the next processing job to? Do I keep a variable of the last server I passed to and go from one to the other? etc.

What is the best method?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

My KISS Tinpot suggestion would be to use JavaScript upon submitting the form to select a server at random.

A list available servers that the upload page would use should be served up as a JS file from the main server. A cron job should update this list periodically to ensure only alive servers are up for selection.

Simple example:

servers.js (hosted on main server, auto-generated):

/* Auto Generated 01/01/2009 01:01:01 */
var Servers = new Array();
    Servers[0] = "";
    Servers[1] = "";
    Servers[2] = "";

function LoadBalancer_GetIP()
    return Servers[Math.floor(Math.random() * Servers.length)];


        <script type="text/javascript" src="servers.js"></script>
        <script type="text/javascript">
            function DoUpload() {
                TestForm.action = "http://"+LoadBalancer_GetIP()+"/upload.php";
        <form id="TestForm" method="POST" action="">
            <input type=button value="Upload" onclick="DoUpload()">
share|improve this answer

Might be going off the hook, but, could you reproduct round-robin / dns / using a method of random requests?

share|improve this answer

Please reconsider, what are those jobs you're trying to break up? What kind of jobs.

First for the answer, you could split jobs evenly based on some parameter of the job, like let's say, each parameter comes with a username field, that submitted the job. You split your userbase between those servers and send appropriate request to designated server.

Other strategy - more complex one - would be for the load balancer to recive some basic info from those 3 workers, which would tell the load of each of them, than distribute jobs basing on that load.

I personaly would go for the complex method, of course if given subject would require that.

share|improve this answer

Your Answer


