How to Optimise WordPress for High Traffic | StudyObject

Memory plays an important part in any software application. Memory allocation is crucial when dealing with high traffic WordPress website.

High Traffic Website

While working on WordPress over a decade, we always wondered if a WordPress site can handle huge traffic. The answer is yes. WordPress is built on mysql and PHP. WordPress has done huge improvement over time.

We will discuss few important steps to optimise your WordPress site to handle huge traffic.

WP_MEMORY_LIMIT allows to specify the amount of memory that can be consumed by a single PHP script. This setting also needs to be changed in the event you receive a message such as “Allowed memory size of xyz bytes exhausted”.

WP_MEMORY_LIMIT

WP_MEMORY_LIMIT is defined in wp-config.php and The default value of WP_MEMORY_LIMIT is 40MB.
define( 'WP_MEMORY_LIMIT', '40M' );

WP_MEMORY_LIMIT variable limits the usage of memory (RAM) by a single PHP script to 40MB.

What is the use of WP_MEMORY_LIMIT in wordpress?

Let’s say your WordPress website has multiple plugins. Each plugin needs to run to provide different features. With the WordPress default setting each PHP script (theme, plugin etc) can get a maximum of 40 MB of memory to run. Many plugins might not be able to run with 40 MB memory limitation. Heavy plugins like woocommerce needs minimum of 128MB of memory to run. Check woocommerce memory req here.

Change the value of WP_MEMORY_LIMIT  to higher value depending on the plugin/theme requirement.I am changing as per woocommerce memory requirement. 
define( 'WP_MEMORY_LIMIT', '128M' );

After update, 128MB is the maximum memory which can be used by any of plugins/ theme.

Does it mean that WP_MEMORY_LIMIT value should be very high like 1024 MB? The Answer is no. 
Because it will allow each plugin/theme to use 1024 MB of RAM. Poorly optimised plugin/theme can use more memory and exhaust the ram. 
It is advisable to keep the value of WP_MEMORY_LIMIT to as low as possible.
The best approach is to keep it to a value required by a plugin which needs highest memory.

Will it work with the above change?

The updated value will not take effect if php memory setting is not updated.

Go to PHP.ini file and change the line as follows

 memory_limit = 128M ;

what should i do if i do not have access to PHP.ini file?

change below line in .htaccess file public_html folder as follows

php_value memory_limit 128M

What is the use of WP_MAX_MEMORY_LIMIT in WordPress?

WordPress has provided another variable WP_MAX_MEMORY_LIMIT in wp-config.php for memory optimisation. WP_MAX_MEMORY_LIMIT is mainly used for admin activity in the backend which is not that concurrent in nature.

INTERESTING FACT 

You must set WP_MEMORY_LIMIT for applying memory restriction on each php script so that the WordPress website does not face memory exhaustion even if many concurrent front end users are accessing the website. If any front end activity takes place which causes a plugin and theme to use more memory than WP_MEMORY_LIMIT , then WordPress uses WP_MAX_MEMORY_LIMIT to redefine the memory restriction.

Difference between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT

The WP_MEMORY_LIMIT  defines the default limit set mainly for front-end task initiated by visitors of the WordPress website, but it can also be raised up to WP_MAX_MEMORY_LIMIT for high end task executed in the backend due to the front-end visitor or for any backend admin activity.

What is your thought, we will love to hear in comment section.

We recommend a site audit . For more optimisations , Give it a Read Here.

Author: Rajnish K

About Author :

Rajnishk is a Serial Entrepreneur, R&D Expert and is passionate for Web Stack. He can be reached at [email protected]

 

 

StudyObject © 2020. All rights reserved.
X