This example describes how PHP uses text statistics to access the volume. Share to everyone for your reference, specific as follows:
Method 1:
$fp = fopen ("Counter.txt", "r+");
while (!flock ($FP, LOCK_EX)) {//acquire a exclusive lock
//Waiting to lock the file
}
$counter = Intval (fre AD ($fp, FileSize ("Counter.txt"));
$counter + +;
Ftruncate ($fp, 0); Truncate file
fwrite ($fp, $counter);//Set your data
fflush ($FP); Flush output before releasing the lock
flock ($fp, lock_un); Release the lock
fclose ($FP);
Method 2:
counter.php file:
<?php
/* Counter
///opens countlog.txt to read the number
of hits $datei = fopen ("Countlog.txt", "R");
$count = fgets ($datei, 1000);
Fclose ($datei);
$count = $count + 1;
echo "$count";
echo "hits";
echo "\ n";
Opens Countlog.txt to change new hit number
$datei = fopen ("Countlog.txt", "w");
Fwrite ($datei, $count);
Fclose ($datei);
? >
Usage:
<?php
include ("counter.php");
? >
More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.