"changing xml-file using php"-problem

I’m combining flash, php and xml to make an online game. When you play the game and enter a room, you load a php-script that gets data from the swf and then rewrites a xml-file.

The problem is that when two users call the php script somewhat at the same time, one of them will not be recorded because the other will overwrite the file with the adapted old file.

Are there any ways around this? I don’t think you can change an xml file (using php) without rewriting it, is it possible to change for instance the value of an attribute?

Hope I’m making sence.

create a new file for each user, ? or temp file… (php aint got nothign to do with it. )

That’s a good idea, but then I’d have to make a script that reads 500 text-files at the same time and i’m affraid that will slow it down. A temporary file sounds good, but how does it work?