Php uses the text statistics method. _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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);?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.