Php uses the text statistics method ,. Php uses the text statistics method. This article describes how php uses the text statistics method. For your reference, refer to Method 1: $ fpfopen (c php uses the text statistics method,
This example describes how php uses text to measure traffic. We will share this with you for your reference. The details are as follows:
Method 1:
$fp = fopen("counter.txt", "r+");while(!flock($fp, LOCK_EX)) { // acquire an exclusive lock // waiting to lock the file}$counter = intval(fread($fp, filesize("counter.txt")));$counter++;ftruncate($fp, 0); // truncate filefwrite($fp, $counter); // set your datafflush($fp); // flush output before releasing the lockflock($fp, LOCK_UN); // release the lockfclose($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:
<?phpinclude("counter.php");?>