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.
- Modify the table so that some tables have redundant fields so that queries do not have to query the table more often
- 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.