|
Posted by Treefrog on 05/04/06 18:05
William Gill wrote:
> I have a PHP user form that I supply a serial number for response
> tracking. The serial number is kept in a simple text file
> (tracknum.dat). When someone submits the form, PHP reads the number,
> increments it, writes the new number to the file, and sends the number
> back to the user for tracking purposes. To prevent two users from
> getting the same serial number I put a delay loop in the script using
> while(file_exists(tracknum.lock). tracknum.lock is created before
> tracknum.dat is opened, and deleted after the new serial number is
> written. This seems to work, but it could cause an infinite loop if for
> some reason the lock file doesn't get deleted by the previous user. Am I
> being paranoid about the possible infinite loop? Is there a smarter way
> to do this?
Nope, it works with poplock files. If you're worried, find out how old
the file is, if it's more than say 5 minutes, assume a previous error,
and delete it/carry on.
[Back to original message]
|