Technical Analysis of WordPress structure advantages and disadvantages

Source: Internet
Author: User
Tags wordpress blog
ArticleDirectory
    • Insufficient WordPress source code
    • Postscript:
    •  

I still feel that I have built an independent blog platform. I often use Linux servers, so I chose the PHP environment. In this way, there will be many open-source blog systems I can choose from. This document does not provide a vertical comparison of the blog system. Let me talk about the process of understanding WordPress and some of my own experiences. It is purely personal opinion. Welcome to discuss it!

 

At the beginning, download a set of WordPress 3.5 and install it all the way. It is relatively simple and cannot be found with some common open source platforms. You only need to configure the database connection and perform the next step. This is also because WordPress has long been heard, and it feels very famous. This type of system is the best.

    • First, let's look at its database structure.

 

The 11 tables provide powerful blog functions, which are not simple at first. At present, many CMS basically have 40-50 tables. There are several tables, which are designed as narrow tables, which are similar to the type, key value name, and key value. Similar to nosql databases in recent years. All are key-value pairs. Flexible reading and convenient extension. It may be complicated during development. This type of basic design is: posts, postmeta table, all the general fields available in the article, put them in the posts Table, and set attributes for the article, such as the number of tokens, tags, permissions, etc. All are placed in the postmeta table. For example:

Narrow tables. You can add key values to any article to expand new attributes. This is also the reason why WordPress plug-ins can do almost everything. This type of table can be very flexible. To add an attribute, you only need to add a record for this type of attribute to the posts ID in this table. In addition, such narrow tables have fewer fields and fast reading speed.

I feel that the table design is insufficient (I personally think, please contact us)

Posts table fields,There are actually 6 text fields in a table.. If you accidentally select * during reading, the disk I/O, a record, and the amount of data blocks will be occupied. I remember that this was the case when I analyzed WordPress. I decided to give up the system. So I ignored it because of its narrow table design advantages. In my opinion, some fields can be set to varchar, and text can be moved to a separate posts_data table. It only stores the text field and postid information. Thank you for your advice.

 

    • Let's look at itsCodeRight
 

Currently, there are hundreds of WordPress plug-ins, which can basically be used in various systems. In addition to blogs, it has also been changed to news websites, enterprise websites, movie websites, and even mall systems. This is enough to show that his front-endProgramThere must be an extraordinary design architecture that is flexible enough.

    1. Check his directory structure.

 

From these directories, we have not found its unique superiority. The common MVC structure on the Internet now has an independent template directory. This WordPress can only be regarded as MC, but not v. In fact, the frontend directly calls the functions in the include directory through PHP. For example:

This is also a unique feature of it. Many templates in China will open up their own labels, such as the smarty: {$ smarty. config. AA. WordPress does not have its own tag. It needs to be read and read through functions. It saves you the cost of learning tags, but you also need to know more than N functions. You can understand its functions as defining tags in other systems.

Whether it is a function or a tag, as long as you use these methods on the front-end page to read the data you want, the backend database is actually isolated. In this way, the user is not connected to the database data. To modify the database structure, you only need to call the function to perform the corresponding jump. Front-end pages can also be used in that way. Without any modification. To ensure its stability.

Function encapsulation not only reads data from the database, but also reads data from functions, read templates, read Public inclusion files, and so on. Function encapsulation. Almost all data reading is encapsulated (in dB, file, request). This encapsulation is rare in Chinese systems because a bunch of functions are written for each function, A lot of work is required. In the domestic framework, you basically like to set up a method, which is very common. Then you can call it on your own. This method may read user tables, comments, or articles. As a matter of fact, it looks very common, and it will be complicated to use in practice, and it will increase the difficulty of getting started. Let's look at the WordPress design method.

 

This is only a small part of the functions. It is about 1000 functions. Because,WordPress functions encapsulate almost all data calls. Therefore, frontend development can only call functions. It is easy to use, which is also a reason for its flexibility and widespread use.

2. Check its code implementation advantages

If we say that WordPress only has a powerful database, it achieves direct separation between front-end pages and data. Currently, many tag calls can also be separated. Real WordPress flexibility, as well as the ability to expand various plug-ins to complete unique development features, is inseparable from its independent system.

It has a message mechanism and a queue Filtering module and a task queue processing module. These two modules are built on a messaging mechanism. The common development method is as follows:

Message Mechanism, which can be achieved, and the frontend and implementation are decoupled. For example, if a user completes registration, I want to send an email to the user and then send an insite email to the Administrator. Our previous practice was:

If you still have a text message after sending the insite email, you must modify the registration logic and then add the function of sending the SMS. At this time, you find that any front-end modification must be modified in the original logic. If we adopt the message mechanism, the program will become:

 

The figure shows the result of switching to the message mode. The user registration function module is directly related to the tasks that receive the message and process the message, and the code is not directly associated. If you need to add a new module to receive registration messages and notify others, you only need to add a new module, customize registration messages, and then process a new process.

Currently, message mechanisms have become very common in various open-source projects. However, in the Wordpress blog framework, the message topic is perfect. Almost any action has a message topic to send messages. In this way, developers can customize related topics and add their own additional processing functions. For example, after a user posts a post. Check whether the user has ad information. You only need to customize: post messages, and then add new features to detect content. If the content is not met, the post will be blocked directly.

It is estimated that many frameworks have similar features like this. For example, there is a start event at the beginning of the page and an end event at the end of the page. Indeed, the message concept is useful in many frameworks. However, the message topic is not completely throttled.Messages are available for almost any operation on the entire system, so there is no function to be extended..

If you are interested, you can study WordPress add_filter, apply_filters, add_action, and apply_action. After receiving the message, you can filter a series of metadata in order, and receive the metadata, for a series of tasks.

WordPress has two major advantages: function encapsulation of data operations and message function improvement.So what is its determination?

    • Insufficient WordPress source code

 

Any system has advantages and will certainly be unsatisfactory.

First, because it needs to implement many functions, it can directly read some cyclic data. You can also directly read the database configuration items. When it starts,A large number of global variables are used.. A large blog may contain hundreds of global variables after startup. Some are data records, some are strings, and some are objects. You may find that the data may be 1, 2 m; whether used or not, these data will be created first. As you can imagine, it will bring a lot of memory waste. The other is that the call speed may be affected. Many netizens have this feeling when using WordPress.

Another problem actually comes from its message processing module. It is different from what we see on the Internet,Its message module is a synchronization module.. For example, even though messages are sent, they are separated from the code of the processing module. In fact, the execution process has not changed much. You must register the user first and then complete some column processing functions. It is best to finish processing this PHP page. It takes some time. If it is true, it can receive messages that are not related to the function, and the processing module is asynchronous to the backend. No one complained that it would take four or five seconds to open WordPress.

 

    • Postscript:

That's all. Many people tell me. In fact, it has poor performance and is slow. What do you need to use it? This depends on what you focus on. If you need quick development templates, and it is very easy to develop various extensions. So it is your best choice. Moreover, the performance problem is almost solved after static.

It may be said that since you mentioned some shortcomings in performance, you have no tuning method. Well, you are welcome to exchange comments here. I have some ideas, so I will not elaborate on them, but I am not mature yet. Welcome !!! Have a good weekend!

 

Author: chengmo QQ: 8292669
Http://blog.chacuo.net/67.html
Subscription keep-in: http://blog.chacuo.net/feed
This article is copyrighted by the author. You are welcome to reprint it. Please add the original article link.

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.