Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:15:58+00:00 2026-06-10T23:15:58+00:00

I am thinking of making a poor man’s application level load balancer for static

  • 0

I am thinking of making a poor man’s application level load balancer for static content (i.e., images). I was wondering if this is the best way to do it. Let me explain in code:

Sample HTML page:

<html>
<body>

<?=load_image('filename.jpg');

</body>
</html>

Sample code in PHP:

<?php

function load_image ($file)
{
    $server = get_current_server();
    update_next_server($server);        

    return '<img src="'.$server.$file.'" />';
}

function update_next_server ($server)
{
    $a[1] = 'server1.com';
    $a[2] = 'server2.com';
    $a[3] = 'server3.com';

    $server_id = array_search($server, $a); // example: if $server = 'server2.com' then this will return 2;

    // increment next server id
    $server_id = $server_id + 1; 

    // prevent going beyond valid server ids
    if ($server_id >= 3)
        $server_id  = 1; 

    $db->query('UPDATE tbl_next_server SET server_id = "'.$server_id.'" '); 
}

function get_current_server ()
{
    return $db->query('SELECT server_id FROM tbl_next_server');
}

Basically this assumes the same images are stored in all three server and it just rotates the server every time the page is viewed.

Now my question is, is this the best way to do this or are there better ways?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:16:00+00:00Added an answer on June 10, 2026 at 11:16 pm

    In your code – 2 queries for image one. Isn’t it too much?

    You must watch what loads more – database\filesystem\memory\processor load? Depending on this solution can be provided by in many ways. For example if DB is overloaded, u can try to store last_server_used value on disk (e.g. in session storage).

    P.S. Anyway i dont see any reason to output images\static(e.g.) with any php code. It’s nginx job to output static content. So i highly recommend you to try write same balancer on other server configuration files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am thinking of making a hidable/showable menu on my web application. Before this,
I'm thinking of making an application where at some points a graph is displayed
I am thinking of making an (initially) small Web Application, which would eventually have
I was thinking of making a commercial application to sell to customers to install
I'm thinking about making a simple web application to practice custom tags, EL, ...
I have an ASP.NET web application that I am making and I am thinking
I'm thinking about making an application that makes audio in a Java application. The
I am thinking of making an application that requires extracting TEXT from an image.
I'm working on administrative application. I was thinking about making it fully AJAX-ed. Basically,
I was thinking of making settings.py start the process but this seemed slightly ugly.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.