How to reduce database access times

Source: Internet
Author: User
Use PHP to write a blog site, articles and other data stored in MySQL.

Page layout is: There are about two sidebar, the middle of the content of the article.
The left sidebar shows the number of categories and articles, the right sidebar shows the latest articles, latest comments, latest messages, and more.
To access five times MySQL to get this data from the sidebar,
Plus the article content and comments, so that every read an article to visit more than 7 times MySQL.

Lions to ask, in the face of this situation,
Are there any techniques or ways to reduce the number of MySQL visits?

Reply content:

Use PHP to write a blog site, articles and other data stored in MySQL.

Page layout is: There are about two sidebar, the middle of the content of the article.
The left sidebar shows the number of categories and articles, the right sidebar shows the latest articles, latest comments, latest messages, and more.
To access five times MySQL to get this data from the sidebar,
Plus the article content and comments, so that every read an article to visit more than 7 times MySQL.

Lions to ask, in the face of this situation,
Are there any techniques or ways to reduce the number of MySQL visits?

Data caching, and table design optimization

Table design optimizations such as:
Left sidebar display categories and article number fields can be designed to: CATID catname articlenum (number of articles)
Each time a new article corresponding to the category Articlenum + 1, so that the left column originally need to query 2 database, now only need to query once, query time can do a persistent file cache, new articles added or new categories added when the file is purged, regenerate the cache file

Data caching such as:
The middle of the article content and title can be completely cached, not very change things
To similar to the latest articles, the latest comments and messages can be seen to add the frequency level to see if you can also cache under the latest n, add articles, comments, leave a message when the cache is deleted

For applications such as reading and writing, it is important to consider the static page.
The practice is to post a blog with PHP to read the database, generate HTML files, all access links to the generated HTML file.

Putting the data together on a redis can greatly improve the speed.
In addition, why not use some mature blog open source code (such as WordPress), you have to make one? Is it a research purpose?

This is going to have to be cached, look at this.

Caching design patterns for Web applications Http://robbinfan.com/blog/38/orm-cache-sumup

Static content, generate HTML once every time the data is changed

This allows you to access MySQL more than 7 times per article read.

For you, it is not the number of visits that counts, but the execution time of each SQL.

    1. Modify the table so that some tables have redundant fields so that queries do not have to query the table more often
    2. Caching is definitely a big move, but pay attention to data Consistency (the lesson of blood)

If you want the page to load faster, you can
1. Page static
2. Open the skylight, generate the module data by JS

Welcome to add Other

Give you two words "business", search it and solve it.

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