所以我有一个带有数字的文本文件。此文本文件保存在服务器上。当有人下载我的文件时,我的数字会增加一个。我今天早些时候知道,总数是87.但我刚刚检查了几分钟,它出现在11点。
任何人都知道这可能是什么原因以及如何避免这个数字不准确?这是我使用的php代码,以便文本文件中的数字增加。
<html>
<head>
<title>Downloading False Logics</title>
</head>
<body onload="SendFile()">
<script language="JavaScript">
window.name = 'main';
function SendFile() {
window.location.href = "Downloadable/False%20Logics.exe";
}
</script>
<?
define("HITCOUNT", "fldownloadcount.txt");
/*design by Mark Le Roy @ http://www.helpvid.net*/
function addOne() {
$fh = fopen(HITCOUNT, "r");
$count = fread($fh, filesize(HITCOUNT));
fclose($fh);
$count = $count +1;
$fh = fopen(HITCOUNT, "w");
fwrite($fh, $count);
fclose($fh);
}
/* count Variables */
function getcount() {
$fh = fopen(HITCOUNT, "r");
$count = fread($fh, filesize(HITCOUNT));
fclose($fh);
/* display Variables */
return $count;
}
addOne();
echo "This has been downloaded ";
echo getCount();
echo " times now since 1/16/2016."
?>
</body>