Last update: 24 of April of 2020
Table of contents
- Cache in WordPress
- PHP in WordPress
- Programmer of tasks (Crones)
WordPress is a stable system but that depends on the yield of the operating system, Web server, PHP and data base to work correctly. To the being a software executed in the servant, whenever a user arrives executes himself completely.
It is by that some improvements and changes for the improvement of the yield of all the system are recommended.
Cache in WordPress
WordPress by defect is 100% dynamic one, which means that whenever somebody accedes is had to generate everything completely, which has a very high calculation. Some of these elements that can slow down the processes are consultations to the data base, the own execution of PHP, external calls to API¦
It is by that it is recommended to frisk. This process allows to previously reuse results calculated in several occasions following a series of rules, which reduces the consumption of repetitive tasks.
Normally the cache renews according to spends a period of predefined time, so that during the time in which the cache is active the results are given back quickly, since usually they recover of the disc or of the memory and they are not had to calculate.
Many layers of cache exist, and in each of them it is possible to be acted of a different way. WordPress, jointly with configurations of the system and plugins, is able to use them. Generally usually they are called in this order:
- Cache of the navigator, I broke the premises or Web App Manifest
- CDN (Content Delivery Network)
- Cache of page, in Web server or proxy
- Cache of page, statics or by PHP
- Opcode I broke
- Cache of objects
- Fragment cache
- Transient API
- Basic cache of data
- Cache of files in disc
Each system of cache works of a different form, can be in the same servant or in several, it can be in the same domain or in different, in it even can be a chain of calls. In addition, each system of cache can require certain configurations that are not qualified by defect, as it can be a different storage, different ram memory, physical connections, latency times¦ this means that the optimization of the cache, in many cases, also will depend on the configuration of the machines that manage them. For example, the access to the ram memory is faster than the access to a disc SSD that is faster than the access to a disc HDD.
Cache of the navigator
The navigators Web who we used to visit the sites allow to store information that can be needed in several occasions throughout navigation by the site. For that reason it is very probable that the first visit to a website goes slower, but later the speed of load increases, since it leaves from the information is stored.
An example would be the one to add to the file .htaccess (in the case of using a Web server Apache httpd) with the following content, that it forces to store to the different types the indicated seconds:
CDN Content Distribution Network
In addition, generally, the also present CDN as a cache layer, since when having the contents and to only serve the static ones, they do not have to make calculations and are optimized to use as rapidly as possible. In case of working with several layers of cache, you have to make sure that purge in all the levels, because a cleaning in a level can become, but not in another one, and to continue using something that has not been invalidated.
Cache of page
When a request becomes of a page, for example the main one of a blog, several processes in PHP are executed, becomes the calculation for the recovery of the contents in the data base, customized configurations calculate and finally it is painted by screen. In many occasions, the contents between a request and another one have not changed reason why why not to show the information calculated in first of those two occasions?
The best form to realise cache copies usually is to put a system between the user and the Web server. Of that form the information is asked for, it uses, and later the changes are verified or it is left equal until the information is invalidated. This intermediate layer can be proxy, habitually managed by tools as nginx (to review proxy) or Varnish Cache that store a copy of the request and serve it until the system is automatically invalidated of form manual or when it arrives at the time of expiration. These systems usually store a copy in memory, so that it uses much more fast that of any other system.
In case of not having a system of this style, always the possibility fits of realising that copy in the own Web server; it is not the fastest option but always it will be better than to have to calculate everything. The majority of plugins of cache that there is for WordPress uses this system.
In the case of the images, scripts, style sheets and similars, the best thing is to serve them directly if they exist and not to happen through systems of processing as PHP.
In case of using anyone of these systems, it remembers that always he is useful to have a system that is invalidating the information, for example, when is published new in the site. The best thing is than a system can be used that only eliminates those pages that are affected and not all the site.
It also remembers that there will be pages that are not due to never frisk, since they are different for each user, as for example the page of the shopping cart of an electronic commerce, or the later process of payment and.
Another element to remember very at the time of forming them cache is the habitual time in which the information until will keep it is invalidated. For example, a corporative Web could frisk the information 1 week, a blog in which it is published with little frequency, with once to the day would be sufficient but, however, an electronic commerce perhaps only 1 hour.
Opcode I broke
Whenever a request arrives at your Web server, PHP has to execute itself and to calculate everything, but PHP allows an internal system of cache of operations, which means that a copy of each execution in memory or disc is stored. If he is active and the same operation is executed again, the system will take advantage of this system to give back the much more fast calculation, since it does not have to calculate everything completely.
If your supplier of hosting has it formed assets and, you can make use of him, but always considering that you will need plugin to make the annulment of the contents when it is necessary.
Cache of objects
Many versions ago of WordPress that we have the possibility of storing some elements in the call I broke of objects. These objects mainly usually are associated calculated elements pre to consultations search.
Thanks to this system and with the help of servers of external storage as memcached or Redis we can store to the calculated datas in some systems thought for a very fast reading without having to store them in the data base. Of this form, the system will not have to return to execute the calculations but they will be read directly of a storage.
Interesting of this system is that not page frisks all the calculated, but parts of her, which does yes that in pages that cannot be frisked completely, that does it certain parts that they do not have because to change.
This type of cache allows to have cache by parts within the set of a same page. The known system more is ESI (Edge Side Includes) and that, with external systems that supports it, would allow to have several frisked parts and to fuse before offering to the final client.
With this system, for example, a page of a store could be frisked by parts, being able to have a common part and other separated parts, as for example the cart that would vary according to each user and it would only change if something in him is added.
PHP in WordPress
Without a doubt the PHP yield is basic for the correct operation of WordPress, since the majority of the system depends on it. It is by that the optimal configuration of PHP in your hosting is essential. PHP is an interpretive language that is executed in the servant, therefore, the weight of the optimization is there.
Version of PHP
Without a doubt for the good operation of WordPress we would have to use PHP 7.x, at the moment recommendable PHP 7.4.x, PHP 7.3.x or PHP 7.2.x. It is known that the versions previous to PHP 7.x (that is to say, PHP 5,6 and previous) they have a yield a 30% minor who the present versions. In addition, in PHP 7,1 a significant change with regard to the coding became, reason why it is recommended to use at least that version.
You have to also have presents that the PHP version has to go in correlation with the version of WordPress that you have. Very old versions of WordPress now would not work with most modern, reason why it is recommended to update everything of parallel form as far as possible.
Also you have to remember very themes and plugins in use. Although WordPress 5,0 gives support to versions of PHP 5,2 until PHP 7,3, plugins usually does not give support to all the versions, reason why to maintain a version little updated can mean that plugins very well-known and used does not work correctly.
From WordPress 5,1 there is a more exhaustive control exceeds what PHP versions can be used, and the developers will inform into it, so that recommendations will be made badly on the possible operation of some extension of the nucleus.
From the version of WordPress 5,2, the compatible version number is reduced and support of PHP 5,6 occurs until PHP 7.3.
From the version of WordPress 5,4 the possibility as much of indicating the minimum version of PHP in themes, so that is introduced themes as plugins can indicate their compatibility of PHP versions.
PHP mainly usually forms according to their file of configuration
php.ini that is read according to its execution. In addition, and usually one integrates with the Web server in his CGI/FastCGI versions or their way PHP-FPM.
In case of having a website of high traffic, it perhaps interests the PHP-FPM system to you.
Time of delay (timeouts)
The times of PHP delay have to go in accordance with those of the Web server, reason why this configuration has to go slightly agreed between both systems. For example, it does not have sense to form PHP so that it has a time of 120 seconds if the Web server has one of 30 seconds.
Each process can take a different time of delay, for example following the load of the servant, and is by whom these times of delay are formed, so that those long processes do not leave blocked other processes until saturating the system. It is by that the election of the time of delay will have to go agreed to the load of the servant and the good execution of the processes.
Primary timeout PHP can be established with the directive
This it limits the execution of code and not called them to the library of the system or consultations SQL (except in Windows where yes it does).
The maximum time allowed for the data transfer from the specific Web server to PHP with the directive
Normally it is used to limit the allowed time to raise archives. It is important to remember that the amount of time is different from
max_execution_time and defines the amount of time between the moment at which the Web server calls to PHP and the home of the execution.
Limit of memory
The limit of memory used by PHP can be formed in the directives of
Even so, WordPress allows from the configuration file wp-config.php to establish the limits. Of this form if those of the servant are majors will execute those, but those who settles down WordPress are majors, were used those.
it defines (WP_MEMORY_LIMIT, 128M);
This option declares the amount of memory that WordPress must solicit for renderizar the frontal (front-end) of the website.
it defines (WP_MAX_MEMORY_LIMIT, 256M);
As habitually the administration panel (wp-admin) requires more memory, there is a separated configuration for the amount that can be established for the users who have initiated session. This usually is very useful in the load of images (since after the ascent usually they are processed). You can establish it over the limit of the frontal to assure that his panel of administration has all the resources that needs.
Ascent of files
When raising archives multimedia and other contents WordPress using the administration panel, WordPress uses PHP to process the ascents. The PHP configuration includes limits as large as the files than they can be loaded through PHP and in the size of the requests that can be sent to the Web server for their processing. These will have to align themselves with the times of delay of the servant.
The limit in the size of the ascents of individual archives can be formed using
Although there is no an established number, a recommendation that fulfills the majority of the cases can be the one of 32MEGABYTE
The limit in the total size of a request that can be sent from the Web server to PHP for its processing can be formed using the directive
php.ini. The value for
post_max_size must be greater or just as the value for
It is necessary to have present that
post_max_size is applied to each request PHP and not only to the ascents, reason why can be important to try separately if a site processes a great amount of other data in each request.
Programmer of tasks (Crones)
For the good operation of WordPress they are had to execute a series of tasks. These tasks are not executed in first plane, but in background, reason why somehow it is had to send a something that executes them. It is by that whenever a usuary one visits the page sends the system of WP-Cron (
Although this control usually does not consume many resources, if a website has much traffic, can be saturated the system. In the same way, if a site has little traffic, perhaps these tasks are not executed with the recommended frequency.
In these cases, the best thing is to deshabilitar the system of crones by means of the configuration of wp-config.php.
it defines (DISABLE_WP_CRON, true);
In this case, you would have to raise, for example, to form in the own servant the execution of the same of form manual by means of the WP-CLI use. In this case one forms his execution every 5 minutes. Unless you have a site of high traffic or with high requirements (as an electronic commerce) would have to be sufficient every 5 minutes, but the execution can be reduced to every minute.
*/5 * * * * WP_CLI_PHP=/usr/local/bin/php; SHELL=/bin/bash; /usr/local/bin/wp cron event run --due-now --path=/home/example.com/public_html/ >/dev/null 2>&1
In case of not having WP-CLI, always use can be done directly of the call of public form, although he is recommendable by security to limit the calls the IP that make the requests (the own machine or the external service that make requests).
*/5 * * * * wget - q - Or - https://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
A more extreme case, and than requires something of knowledge of programming in PHP and shell, could be the one to create a small code in PHP that executes cron in the premises, so that it does not have to accede of external form.
For this we would create a file PHP with the following code (for example of
<? php to chdir (/home/ example.com/public_html/'); //the absolute route where is WordPress include (wp-cron.php);
And that we would call from cron with the following consultation:
*/5 * * * * /usr/bin/php /home/example.com/run-wp-cron.php > /dev/null 2>&1
Many ways exist to make the calls corresponding to the programmed tasks, reason why he is very recommendable that you speak with your supplier of hosting Web so that it recommends the best way to you.