Dx1.5 details about the number of viewing posts and the number of attachment downloads delayed updates

Source: Internet
Author: User
**************************************** *********

** Code Description Based on version: discuz! X 1.5 GBK release 20110121 **

**************************************** *********

The number of viewing posts and the number of downloading attachments are updated in a delayed manner, which can significantly reduce the load on the server (mainly for MySQL) of websites with a large access volume. We recommend that you enable this function. However, many webmasters may not be very clear about the program procedures and functional details. Here, I will give you a string of texts, hoping to encounter problems in the future, we can provide you with some ideas.

I. How to enable delayed update


Involved files: Source \ admincp \ admincp_setting.php

Search Keyword: delayviewcount


Enable delayed update. In the global optimization Settings> server Optimization on the background of the Forum, select the check box under click delay update as needed. This is very simple.

Under "delayed update of clicks", "topic views" and "attachment downloads" are set, but they are saved in delayviewcount of the same configuration item, so here we do some small processing on the program. The two submitted options are: if the value is 1 and the value is 0, it is spliced into binary characters, then convert it to decimal and save it to the database. That is:
The attachment downloads are disabled at 0, the topic page views are disabled at 0, the binary number for splicing is 00, And the decimal value is 0;

The attachment downloads are disabled with a value of 0, the topic page views are enabled with a value of 1, the binary number for splicing is 01, and the conversion is in decimal format;

The attachment downloads are enabled with a value of 1, the topic page views are disabled with a value of 0, the binary number for splicing is 10, and the conversion is in decimal format;

The attachment downloads are enabled with a value of 1, the topic page views are enabled with a value of 1, the binary number for splicing is 11, and the conversion is in decimal format of 3.

Therefore, when the value (skey = 'delayviewcount') stored in the data table (pre_common_setting table) is 0, 1, 2, and 3.

Ii. Actual use of topic page views with delayed update


Involved files: Source \ module \ Forum \ forum_viewthread.php

Search Keyword: function viewthread_updateviews


Involved files: Source \ function \ function_misc.php

Search Keyword: function updateviews


The number of views of a topic is the number of views. When you browse a topic (access the forum_viewthread.php file), the number of views of the topic is added to 1, this action is performed in the function viewthread_updateviews (near line 695 of the forum_viewthread.php file. If delayed update is not enabled, 1 is directly added to the Views field in the topic record of the pre_forum_thread table. According to the value in the background settings ($ _ g ['setting'] ['delayviewcount'], refer to the Enable relationship of the preceding values, when the values are 1 and 3, the topic page views are updated in a delayed manner.

Delayed update clicks will generate a. Log File starting with forum_threadviews in the data/cache directory. Therefore, the server must grant this directory read and write permissions. Every TID of the topic that needs to increase the number of clicks is written to this file and occupies one row independently. At this time, no write operations are performed on the pre_forum_thread table to delay update.

When any user accesses the topic browsing page (accessing the forum_viewthread.php file), the end two digits of the system timestamp value are 00, the cache hits will be updated to the database at one time. If you do not understand the timestamp of the system mentioned above, it is understood that 00 is equal to 100 seconds, that is, an update will be triggered every 100 seconds, the second 100 represents the time point of a whole point in seconds, rather than the interval of 100 seconds. Therefore, an update MUST be triggered at a certain time point, instead
An update will occur in 100 seconds.

For example, if the current time is midnight 00:00:00 and the time is 00:01:40 after 100 seconds, the update will be triggered only when a user accesses the theme page at 00:01:40. If no one accesses the page, the update will not be triggered, wait until the next 100 seconds after 00:03:20.

After the update is triggered, the updateviews function in the function_misc.php file (near line 299 of the function_misc.php file) is called to Perform Batch update and update the clicks cached by all topics to the database at one time. This process requires the support of the rename function. Therefore, make sure that the data/cache directory is readable and writable.
This function cannot be disabled in the PHP. ini configuration file of PHP, that is, no rename is followed by disable_functions.

Iii. Actual use of delayed attachment downloads


Involved files: Source \ module \ Forum \ forum_attachment.php

Search Keyword: updateviews


Involved files: Source \ function \ function_misc.php

Search Keyword: function updateviews


Attachment downloads: When downloading an attachment (accessing the forum_attachment.php file), the attachment downloads will be increased by 1, this action is performed around the execution of the updateviews function (near line 178 of the forum_attachment.php file. If delayed update is not enabled, 1 is directly added to the downloads field in the attachment record of the pre_forum_attachment table. According to the value in the background settings ($ _ g ['setting'] ['delayviewcount'], refer to the Enable relationship of the preceding values, when the values are 2 and 3, the delayed update of attachment downloads is enabled.

Delayed update clicks will generate a. Log File starting with forum_attachviews in the data/cache directory. Therefore, the server must grant this directory read and write permissions. Each Aid of the attachment that requires additional downloads is written to this file and occupies one row independently. No write operation is performed on the pre_forum_attachment table to delay the update.

When any user downloads an attachment (accessing the forum_attachment.php file) and the end of the system's timestamp value is 0, it will trigger the cache downloads to be updated to the database at one time. If you do not understand the timestamp of the system mentioned above, it is understood that 0 is equal to 10 seconds, that is, an update will be triggered every 10 seconds, the 10 seconds here represent the time point of a whole point in seconds, instead of the time interval of 10 seconds. Therefore, the update MUST be triggered at a certain time point, instead of an update that will occur after 10 seconds.

For example, if it is currently midnight 00:00:00 and 00:00:10 after 10 seconds, an update will be triggered only when a user downloads an attachment at 00:00:10, if no download happens, the update will not be triggered, and it will wait until 00:00:20 next 10 seconds.

After the update is triggered, the updateviews function in the function_misc.php file (near line 299 of the function_misc.php file) is called to Perform Batch update and update the clicks cached by all topics to the database at one time. This process requires the support of the rename function. Therefore, make sure that the data/cache directory is readable and writable. This function cannot be disabled in the PHP configuration file PHP. ini, that is, the disable_functions file does not contain the rename word.

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.