I've built a Flash game and using PHP to save scores to a text file. Everything works fine so far.
My potential problem is that I'm not sure what happens when there are multiple requests to write to the file simultaneously. The file might be corrupted, or the request(s) might fail?
I'm not good at file system functions so I need your help. This is the basic structure of my script:
Expand|Select|Wrap|Line Numbers
- <?php
- $handle=fopen("theScores.txt", "r+");
- $data=fread($handle, filesize("theScores.txt"));
- //prepare the output here
- ftruncate($handle, 0);
- fseek ($handle, 0);
- fwrite($handle, $output);
- fclose($handle);
- ?>
How should I proceed?
Thanks.