Visits counter without database with PHP

前端 未结 5 651
花落未央
花落未央 2020-12-05 08:49

I have a single webpage and i would like to track how many times it\'s visited without using a database.

I thought about XML, updating a file every time a user visit

5条回答
  •  忘掉有多难
    2020-12-05 09:35

    The following works beautifully except for the large file size for too many visits.

    file_put_contents('counter.txt', '1', FILE_APPEND);
    echo '

    Hi, Page served ' . filesize('counter.txt') . ' times!

    ';

    However, after the file reaches 1000 or 1000000, simply create another file which counts that unit as well. Inelegance of the large size is matched by the performance that does not require locking.

提交回复
热议问题