Page 1 of 1

Is this code synchronized?

Posted: Tue Feb 12, 2008 2:22 am
by coltsith
Hi there,

I have a php script for a highscore table for a game I'm making. The basic flow of the code is this:

Code: Select all

Open highscore file (READ mode)
-read values
 
Open highscore file (WRITE mode)
-write new highscore
 
close highscore file (READ mode)
close highscore file(WRITE mode)
I'm doing this because my concern is that if I do this:

Code: Select all

Open highscore file (READ mode)
-read values
close highscore file (READ  mode)
 
Open highscore file (WRITE mode)
-write new highscore
close highscore file(WRITE mode)
That if two players submit a highscore at the same time, they could potentially screw each other up if one read, the other read, then the first one wrote, and the second one wrote, etc.

Is this okay for me to do? If I'm not making sense I can clarify.

Thanks

Re: Is this code synchronized?

Posted: Tue Feb 12, 2008 3:35 am
by Christopher
You may want to look at file locking (flock()).

Re: Is this code synchronized?

Posted: Tue Feb 12, 2008 1:07 pm
by coltsith
Okay thanks!