hi...
here is the code:
$file = "numbers";
$fp = fopen($file, "r+");
if (flock($fp, LOCK_EX)) { // do an exclusive lock
$c = fread($fp,filesize($file));
$c = intval($c) + 1;
rewind($fp);
fwrite($fp, $c);
flock($fp, LOCK_UN); // release the lock
} else {
echo "Couldn't lock the file !";
}
fclose($fp);
very simple stuff. i need to open file get the number in there and then write back to it with the number increased with 1 while no other process can read the file.
fopen($file, "w+") doesn't work in this case.
is there any way to overwrite the file content without actually using rewind?
thanks...