Manuscript traffic statistics, whether the database must be read and written every time you browse

Source: Internet
Author: User
Do I have to read and write the database every time I browse the article traffic statistics? This post was last edited by sky94132003 from 2014-06-2000:50:06. for example, a news system article table is news, & nbsp; open a count column to record traffic? I want to show in the article whether the browsing times are only made in php... the value in the count column is read in news for each access. however, do I have to read and write the database every time I browse the article traffic statistics?

This post was last edited by sky94132003 at 00:50:06

For example, a News system

The article table is news. what is the traffic recorded in the count column?

Display the number of times browsed in the article

Is it made in php only?

Read the value in the count column in news, and then click + 1.

Write again?


In this case, will the load be too heavy when there is a large convection volume?

Can I do this either?

I have used the smarty template engine.
Do you need to pay attention to cahac in addition to local operations?



For example ...:
$ Hits_now = $ row ["hits"] + 1;
$ Pdo-> exec ("UPDATE 'news' SET 'hits '=' $ hits_now 'Where 'id' = '$ ID '");
So simple SQL statements are directly EXEC, right?
------ Solution --------------------
1. you only need to update the database each time. (if the index of the table where the field is clicked is normal, there is no pressure to view the page below 0.5 million PVs every day.
2. filter and inject statements
------ Solution --------------------
The number of accesses can be stored in the cache, such as memcache or redis. At the beginning of the statistics, the traffic is read and saved in the cache. each user access will add a variable and save it back to the database when the statistical time is reached... In this way, you only need to read and write the database at the beginning and the last two times for each Statistics. Read and write once ..

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: info-contact@alibabacloud.com 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.