0

I save data which come from a form to a file. There is a row number in file. If two or more users submit the form at same time, we expect the row numbers are same. Because before the saving, I read the highest row number for decide new record row number.

How can I prevent that? sys_getloadavg is solution? Thanks.

miqbal
  • 2,213
  • 3
  • 27
  • 35
  • Your question is not clear to me. From what you've written I understand you have a file form. When the file form is submitted what happens? Is there some data written to a database? What are the `row numbers` used for and where do you get it from? – tftd Feb 27 '12 at 02:23

2 Answers2

0

You can do this with a file lock (slow but works on all platforms) or a semaphore. see this thread for details: PHP mutual exclusion (mutex)

Community
  • 1
  • 1
Don Dickinson
  • 6,200
  • 3
  • 35
  • 30
0

Im not sure what you are trying to do exactly, but the requests will never be at the exact same time. One will always be marginally ahead of the other.

If you are talking about editing a file, maybe you should make a configuration file that only lets you open a file in a read mode when another user has it open.

You could then contiously ajax the config file to check if another user has it open and change the state from read to write.

MichaelH
  • 1,600
  • 3
  • 14
  • 20