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 ..