Home  >  Article  >  CMS Tutorial  >  How to optimize WordPress

How to optimize WordPress

藏色散人
藏色散人Original
2019-07-12 11:55:035635browse

How to optimize WordPress

How to optimize WordPress

WordPress optimization experience and skills:

Separation of dynamic and static

No matter whether it is a WordPress blog or a site built by other CMS, the first step in optimization must be the separation of dynamic and static. This is why you see Sina, Tencent and other portals, their pictures The domain name and the domain name of the website are not the same.

There are generally two types of static files on websites: the first is the CSS, JS and common background images and button files of some themes. If the website does not undergo revision or other changes, these images will basically not be used. Will be modified. The second type is the pictures or attachments uploaded in the website content that are updated every day. These picture files will basically not be changed.

After solving static file storage and acceleration, website performance can be basically guaranteed first. The same is true for websites and blogs built by WordPress. For these static files, the best solution is always to use the CDN network for acceleration. In this way, the pressure on the server will be greatly reduced, because only the current page is on your own server when accessing the page, and all other images, JS and CSS are. Obtained from CDN.

How to use CDN services for WordPress blogs? The WPJAM Basic plug-in I wrote already supports three cloud storage services: Alibaba Cloud OSS, Qiniu Cloud Storage and UCloud Ufile. As long as you install the WPJAM Basic plug-in, you can Achieve CDN acceleration of WordPress blog static files with one click.

Server Optimization

After optimizing the static files, we must start optimizing the dynamic content of the website. To optimize dynamic content, we must first have a stable network environment. Stable Hosting provider and server performance optimization.

Choose a reliable hosting provider. I personally recommend BGP or a multi-line computer room, so that users across the country can access it at a good speed. Then try to choose an independent server. Even if it is not possible, you can still get a VPS, because you Many things cannot be done without the root authority of the server. Generally recommended in China: Alibaba Cloud.

After the server problem is solved, the server can be optimized as follows:

Install Memcached and PHP Memcached extension: Use Memcached to cache WordPress data.

PHP Turn on OPCache: cache the compiled PHP code into shared memory, and call it directly when the user accesses it to achieve efficient acceleration.

MySQL Set up MySQL Query Cache to save query results. The same query will no longer be retrieved from the database, which greatly improves the speed.

WordPress Cache

To completely understand and understand WordPress performance optimization, you must first understand the WordPress caching mechanism. WordPress defaults to an object caching mechanism called WordPress Object Cache. , it caches the content that needs to be cached according to the Key-Value pattern (somewhat similar to No-SQL's key-value). Of course, it also supports dividing the cached content according to Group and avoiding cached content conflicts.

So the most basic WordPress caching plug-in is to save the Key-Value generated by WordPress. If you use Memcached, it is saved in the memory. If you use Flie, it is saved in the hard disk. Of course, advanced WordPress plug-ins also It can do more. For example, WP Super Cache caches the entire page to the hard disk and directly accesses the static HTML file next time, allowing the server to directly bypass PHP and save CPU time. Batcache will store the entire page in memory as an object. I personally recommend using Memcached enough.

Memcached will store WordPress objects in memory. The server’s memory is large enough, the reading and storage speeds are fast enough, and the memory cache hit rate is greater than 97%. In addition, after our WordPress program has been optimized, the number of queries on each page is generally about 2, so the entire website is very efficient. The homepage even has 0 SQL, and the page generation only takes 0.0013 seconds.

The WPJAM Basic plug-in has integrated Memcached. After downloading WPJAM Basic, copy the object-cache.php file in the wpjam-basic/template/ directory to the wp-content directory.

WordPress program optimization

WordPress program optimization is based on the WordPress Object Cache mechanism to optimize WordPress plug-ins and themes. The main experiences are as follows:

Only use necessary WordPress plug-ins. Installing too many WordPress plug-ins can easily cause performance problems.

Download WordPress themes from regular sites, so that the quality and safety of the downloaded themes can be guaranteed. We recommend the Autumn and Honey themes released by xintheme and me. Home Page 0 SQL has been implemented.

WordPress themes and plug-ins try to use template functions, because WordPress template functions have been prepared in WordPress Object Cache if possible. For example: the two functions get_the_terms and wp_get_object_terms have basically the same functions, but get_the_terms fetches data directly from the object cache without querying, while wp_get_object_terms fetches data from the database every time.

If you must directly query the database for WordPress plug-ins and themes, please prepare an Object Cache, use wp_cache_set to save the query results to the Object Cache, and use wp_cache_get to obtain them directly next time.

WordPress Performance Optimization Service

To summarize: To optimize WordPress, first download and install the WPJAM Basic plugin. Then choose a good server and hosting provider, optimize the WordPress program, and use Memcached for caching.

WordPress is actually very efficient. Coupled with the flexibility and powerful functions of WordPress itself, WordPress is definitely a very good choice for building various websites, so I always use WordPress to build websites.

For more WordPress technical articles, please visit the WordPress Tutorial column!

The above is the detailed content of How to optimize WordPress. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn