1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Lag in php causing mysql to freak out

Discussion in 'PHP' started by xiosen, Mar 21, 2007.

  1. #1
    Hello Everyone, I seem to be having a major problem and I cannot seem to find the answer.

    The problem I am having is due to the lag in my server is causing the mysql queries to conflict or mess up each other or something. This problem all started when the lag became aparent on my server. Unfortunately that is not something I can fix yet, so I would liek to fix up the coding error.


    I have a field in a table that looks like this:

    money | bigint | 40 | Default: 0 | unsigned


    The problem I am having is that when 2 users call 2 separate scripts with 2 separate queries relating to the same user and updating the same field, mysql freaks out and puts the absolutely maximum value into that field.

    Heres an example:

    One person goes to the bank.php and deposits say 200,000. At the same time another user goes to battle.php and attacks the first person and takes away 100,000. So the remaining value in the field should be 100,000. Because of the lag in the scripts all the sudden the first person has 1.8446744069415E+19 for there money field. As you know, this is exactly the maximum integer for a bigint field that is unsigned.

    Both of the scripts when the but occurs are doing different math operations like so:

    bank.php - Update table set money=money+$deposit where playerid=$id
    battle.php - Update table set money=money-$battleloss where playerid=$id

    So, in conclusion. It seems that calling these 2 queries at the same time results in mysql locking up and then inserting the maximum bigint value into the versus the result of the simple math operations.

    Thank you for any help you can provide.
     
    xiosen, Mar 21, 2007 IP