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

  • SEARCH
  • Home
  • 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 7418143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:49:54+00:00 2026-05-29T07:49:54+00:00

I have an application (php) running with MySQL 5.5 (1 master and 1 slave)

  • 0

I have an application (php) running with MySQL 5.5 (1 master and 1 slave)

I use to dispatch read/write on master / slave.

When I create a new record (a user or something like that) I write it on the master and when I reload the page, I load it from the slave.

Example:

...
if ($_GET['id'])
{
    #Load user
    $user = $sql->load('user', $_GET['id']);

    if ($user == false)
    {
        throw exception('User not found');
    }
}
else if ($_POST['create]')
{
    #Create a new user

    $user_id = $sql->insert('user', $_POST);
    $mvc->reload('?id=' . $user_id);
    exit();
}
...

But when the master is really performant (quick insert) and the replication is not (lag = 0.3 – 1 sec), the reload will not work…

What are the best practice to handle that

Some solutions:

  • Database optimisation for reducing the lag (very difficult)
  • sleep(1) before reading or after writing … not very elegant
  • 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-05-29T07:49:55+00:00Added an answer on May 29, 2026 at 7:49 am

    First, you need to define if your application can work with a lag or not.

    If not, then you need to ensure that the data you want to fetch are already available on slave. For example fetch the last id from slave and compare it with id you are about to fetch; or try slave first and if row is not there, fallback to master (but that will overload the master with requests for new data).

    Usually web application can work with stale data. There is no problem if other visitors will see a new post 10 seconds later. But as you mentioned, it is bad if author of the post doesn’t see it immediately. So you can act differently based on the data/reason you are fetching (for example cache the info about recent post in session and in that case fetch from master)

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

Sidebar

Related Questions

I'm building a PHP/MySQL application and I'm running into a problem with my create
I have a PHP application that displays a list of options to a user.
I have a PHP application that makes extensive use of Javascript on the client
I'm writing a web application (PHP) for my friend and have decided to use
I have a php application running on XAMPP but I want to connect to
I have a PHP application running in iFrame mode. I am rendering an <fb:multi-friend-selector
I have a web application written in PHP. It uses MySQL for data storage.
I have an application running on flex and php, connected using amfphp, i added
I AM NOT RUNNING THE COMMANDS FROM PHP! I have MySQL log_error value set
I have a Php application running on my Server A that consumes a .NET

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.