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 8401101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:43:10+00:00 2026-06-09T21:43:10+00:00

I have a website running PHP+MySQL. It is a multiuser system and most of

  • 0

I have a website running PHP+MySQL. It is a multiuser system and most of the MySQL tables are MyISAM-based.

The following situation got me puzzled for the last few hours:
I have two (concurrent) users A,B. Both of them will do this:

  1. Perform a Read Operation on Table 1
  2. Perform a Write Operation on another Table 2 (only if the previous Read operation will return a distinct result, e.g. STATUS=”OK”)

B is a little delayed towards A.

So it will occur like this:

  • User A performs a read on Table 1 and sees STATUS=”OK”.
  • (User A Schedules Write on Table 2)
  • User B performs a read on Table 1 and still sees STATUS=”OK”.
  • User A performs Write on Table 2 (resulting in STATUS=”NOT OK” anymore)
  • User B performs Write on Table 2 (assuming STATUS=”OK”)

I think I could prevent this if Reading Table 1 and Writing to Table 2 were defined as a critical section and would be executed atomically. I know this works perfectly fine in Java with threads etc., however in PHP there is no thread communication, as far as I know.

So the solution to my problem must be database-related, right?
Any ideas?

Thanks a lot!

  • 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-09T21:43:12+00:00Added an answer on June 9, 2026 at 9:43 pm

    The Right Way: Use InnoDB and transactions.

    The Wrong-But-Works Way: Use the GET_LOCK() MySQL function to obtain an exclusive named lock before performing the database operations. When you’re don, release the lock with RELEASE_LOCK(). Since only one client can own a particular lock, this will ensure that there’s never more than one instance of the script in the “critical section” at the same time.

    Pseudo-code:

    SELECT GET_LOCK('mylock', 10);
    If the query returned "1":
        //Read from Table 1
        //Update Table 2
        SELECT RELEASE_LOCK('mylock');
    Else:
        //Another instance has been holding the lock for > 10 seconds...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project management website running on PHP and MySQL. But I am
I got very strange problem. I have one php website which is running in
I recently installed xampp, followed the installation. MySQL/apache. (I have same website running on
I've built a PHP based website with MySQL as the back-end, and am planning
I have all my sites in PHP/MySql some are running on Drupal. We need
I have a website running on CentOS using the usual suspects (Apache, MySQL, and
I have a website running with Pyrocms & CodeIgniter. My config is the following:
I have a web app running on php and mysql. i have tested on
I currently have an entire website running on PHP & GET variables. My links
I have the following code running on my website. I call it from a

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.