Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2006
    Posts
    264

    Question php/mysql question

    if i have a website using php and mysql where the first person to click on a particular button wins a prize, what happens if 10 people click on the button at the exact same time including milliseconds? how does php/mysql pick who clicked the button first?

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    The answer depends on how you're testing whether the prize has already been won. If it's an entry in the database you probably need to look at table locking - the first process to get a lock wins.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Mar 2006
    Posts
    264
    what if 2 processes request a lock at the same time?


    Quote Originally Posted by foobic View Post
    The answer depends on how you're testing whether the prize has already been won. If it's an entry in the database you probably need to look at table locking - the first process to get a lock wins.

  4. #4
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Only one would get a lock. Only a major mysql bug could produce any other result.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    You might want to take a look at the docs for select:

    http://dev.mysql.com/doc/refman/6.0/en/select.html

    Specifically search that page for "for update" The SELECT ... FOR UPDATE syntax should provide you with the locking you are looking for.

  6. #6
    Join Date
    Apr 2009
    Location
    localhost
    Posts
    174
    Synchronize the action of posting to the mysql with the time may be in micro seconds.

Similar Threads

  1. mysql question
    By nkad in forum Hosting Security and Technology
    Replies: 2
    Last Post: 12-04-2006, 10:35 PM
  2. Question about VPS & mySQL
    By chihpih in forum VPS Hosting
    Replies: 3
    Last Post: 04-27-2005, 05:03 PM
  3. MySQL question
    By Zhamel in forum Programming Discussion
    Replies: 1
    Last Post: 11-19-2003, 04:56 AM
  4. question (PHP/MySQL)
    By Gamenati in forum Programming Discussion
    Replies: 1
    Last Post: 04-18-2003, 11:58 PM
  5. PHP/Mysql question
    By mjfroggy in forum Programming Discussion
    Replies: 7
    Last Post: 12-23-2002, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •