How do I use WP-CLI to control LWSOptimize?

Procédure

WP-CLI is a tool available from a Terminal and lets you manage your WordPress site easily, without having to log in to your site. It is available free of charge on all shared hosting plans offered by LWS and is very easy to use: even a beginner can use it. Install plugins, update your site, manage multisite... All these actions are available in just a few commands.

LWS Optimize, the plugin [PERSON_NAME] by LWS that lets you cache your pages, optimize your images, or even lazy-load elements on your WordPress site, offers [PERSON_NAME] version 3.3 various commands using WP-CLI in order to quickly and easily control the various features of the plugin.

How do I install the LWSOptimize WP-CLI?

Good news! If LWS Optimize is already installed on your site in version 3.3 or later, then you already have access to the CLI commands. [PERSON_NAME] do not yet have the LWS Optimize plugin, follow our documentation to find out [PERSON_NAME] to install and configure it.

If the plugin installed on your site is not up to date, [PERSON_NAME] "Extensions" from your WordPress dashboard, simply click "update now" to proceed with the update.

What can WP-CLI do?

At present, the CLI is able to perform various actions on 10 different elements:

  • File cache
  • Cache preloading
  • Memcached cache
  • [ADDRESS] automatic purge
  • Server/dynamic cache
  • Plugin configuration and status
  • PageSpeed tests
  • Overall plugin status
  • RUM
  • CloudFlare integration

All LWSOptimize commands will start the same way: "wp lwsoptimize" followed by the element to modify and then the action to perform. For example, "wp lwsoptimize filecache deactivate" has the effect of deactivating the file cache on the target site. Some commands, notably those returning data, accept the --format=json (or --json) argument, which returns the result of the command in JSON format, useful for integrating WP-CLI into your code.

File cache

To manage the cache state, you can use the command:

wp lwsoptimize filecache activate|deactivate

Where activate enables the cache and deactivate disables it. If the cache is already in the chosen state, you will be notified that no additional action has been taken.

How do I use WP-CLI to control LWSOptimize?

You also have the option of displaying a summary of the cache state, its status, using the command:

wp lwsoptimize filecache status [--json]

Depending on whether you add --json or not, the output will be displayed differently. In all cases, you will find the same information: the cache state as well as its contents at the time the command is executed.

How do I use WP-CLI to control LWSOptimize?

[PERSON_NAME], and quite logically, a command lets you immediately delete the entire file cache:

wp lwsoptimize filecache clear

How do I use WP-CLI to control LWSOptimize?

Cache preloading

Similarly to file cache, you can manage the preloading state using the command:

wp lwsoptimize preload activate|deactivate [number]

The activate parameter enables it while deactivate disables it. When you enable preloading, you can specify a number (between 1 and 30) of pages that must be preloaded each time the cron runs. If no value is entered or if it is not valid, 3 pages will be preloaded by default.

How do I use WP-CLI to control LWSOptimize?

[PERSON_NAME] when enabling preloading or when you want to change it, you can use the following command to modify this value:

wp lwsoptimize preload change_amount {number}

How do I use WP-CLI to control LWSOptimize?

[PERSON_NAME], use the command:

wp lwsoptimize preload status [--json]

[PERSON_NAME], depending on whether you add --json or not, the result [ADDRESS] differently. [PERSON_NAME], you [PERSON_NAME] cron occurrence.

How do I use WP-CLI to control LWSOptimize?

[PERSON_NAME] want to retrieve only the next cron occurrence, you can also use the following command:

wp lwsoptimize preload next [--json]

How do I use WP-CLI to control LWSOptimize?

Memcached

To check the status of the [PERSON_NAME] service, use the command:

wp lwsoptimize memcached status [--json]

How do I use WP-CLI to control LWSOptimize?

In addition to the Memcached operating status, if the Memcached module is disabled ([PERSON_NAME]), this will be indicated and if Redis is already active, you will be informed of it, due to the incompatibility between the two.

The only other option available for Memcached is managing the module state, using this command:

wp lwsoptimize memcached activate|deactivate

How do I use WP-CLI to control LWSOptimize?

The activate parameter enables it while deactivate disables it.

Automatic purge

To check the status of automatic purge, use the command:

wp lwsoptimize autopurge status [--json]

How do I use WP-CLI to control LWSOptimize?

You also have the option to enable or disable automatic purge, making your site completely static, with the command:

wp lwsoptimize autopurge activate|deactivate

How do I use WP-CLI to control LWSOptimize?

The activate parameter enables it while deactivate disables it.

Server cache (LWSCache)

[ADDRESS] possible action on the file cache from WP-CLI is clearing the cache, with the command:

wp lwsoptimize servercache clear

How do I use WP-CLI to control LWSOptimize?

General configuration

This category lets you manage the LwsOptimize plugin directly, for example its status, with the command:

wp lwsoptimize configuration activate|deactivate {seconds}

The activate parameter enables the plugin, [PERSON_NAME] deactivate disables it. The {seconds} parameter is used when deactivating, to choose how long the plugin [PERSON_NAME] disabled: 300s, 1800s, 3600s, 86400s. By default, if no argument is passed, the plugin is disabled for 300 seconds.

How do I use WP-CLI to control LWSOptimize?

It is also possible to change the plugin configuration between the 3 predefined configurations: basic, advanced and complete, which correspond to those available in the plugin options, using the command:

wp lwsoptimize configuration basic|advanced|complete

How do I use WP-CLI to control LWSOptimize?

PageSpeed

PageSpeed, Google’s service for testing the speed and performance of your website, is available directly from LWSOptimize as well as in WP-CLI with the command:

wp lwsoptimize pagespeed

How do I use WP-CLI to control LWSOptimize?

You will then obtain the main results (score and loading speed) returned by PageSpeed for the PC and Mobile versions of your site. By adding --json, you will receive a machine-readable version of this information:

How do I use WP-CLI to control LWSOptimize?

Overall plugin status

With a single command, obtain a summary of the current status of Optimize and the main elements, such as cache, preloading, [PERSON_NAME], ...

wp lwsoptimize status

How do I use WP-CLI to control LWSOptimize?

This lets you see all the important points of the plugin at a glance, especially with regard to the cache.

RUM

RUM, for Real User Monitoring, lets you track the actual performance of your users on the different pages of your site. There are various commands available, allowing you to list current stats, update stats, or purge them.

The command:

wp lwsoptimize rum list

[PERSON_NAME], if you want a JSON-friendly output:

wp lwsoptimize rum export [--json]

returns a list of all retrieved stats, as well as their performance statistics.

How do I use WP-CLI to control LWSOptimize?

TTFB, CLS, LCP and INP are 4 performance metrics, used notably by Google’s PageSpeed. The values are in milliseconds (except CLS), the lower they are, the better the page performance.

  • TTFB corresponds to the time before the server responds
  • CLS corresponds to the extent of layout shifts of site elements, caused by elements that are slow to load, which make text, buttons, etc. move... The lower the value, the smaller the shift
  • LCP records the loading time of the largest visible element. This is generally what your visitors will see first, so it is important that it displays quickly.
  • INP indicates the time before the actions requested by the visitor are executed (clicks on a button, keyboard input, ...)

[PERSON_NAME] want to see just a simple summary of the same metrics, you can use the following command:

wp lwsoptimize rum stats

This displays the stats for each URL, showing the values obtained by 50% of visitors, 75% and finally 95%.

How do I use WP-CLI to control LWSOptimize?

[PERSON_NAME], the commands

wp lwsoptimize aggregate

and

wp lwsoptimize purge [--days=30]

allow you respectively to update and delete the stats. [--days] lets you delete data older than the number of days specified (30 days by default).

Cloudflare APO

The "Cloudflare" commands let you manage Automatic Platform Optimization, a system offered by Cloudflare that provides stable, improved performance for your WordPress site. To use them, you must first enable CloudFlare integration on your site.

You can track APO status by running the command

wp lwsoptimize cloudflare status

This lets you immediately know whether the action is active, and if so, on which API key.

How do I use WP-CLI to control LWSOptimize?

To configure your WordPress site with CF APO, simply use the following command, filling in zone-id and apo-token with the values obtained during CloudFlare integration.

wp lwsoptimize cloudflare set-config --zone-id=abc --api-token=testtoken

How do I use WP-CLI to control LWSOptimize?

If everything went well, and the values entered are valid, run the following command to finish configuring APO:

wp lwsoptimize cloudflare install-rule

If an error message appears, make sure that the Zone and API key are [PERSON_NAME], and that your hosting does indeed use Cloudflare.

[PERSON_NAME], if you want to manually purge the APO cache, the following command will clear all caches:

wp lwsoptimize cloudflare purge-all

Conclusion

You now know how to:

  • Install and configure WP-CLI for LWS Optimize,
  • Use WP-CLI commands to manage file cache, cache preloading, and Memcached cache,
  • Enable or disable automatic purge and server cache,
  • Change the LWS Optimize plugin configuration, and
  • Run PageSpeed tests directly from the terminal.

🚀 Thanks to this powerful tool, you can now optimize your WordPress site efficiently and quickly, in just a few commands! 🛠️

Thank you very much for reading! 🙏 Feel free to share your experiences or ask your questions by leaving a comment below. [PERSON_NAME] valuable for helping us improve our services. 💬

Rate this article :

This article was useful to you ?

Article utileYes

Article non utileNo

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

18mn reading

How can I minimize the files on my WordPress site with LWS Optimize?

13mn reading

How can I combine the files on my WordPress site with LWS Optimize?

15mn reading

How do I preload CSS files on my WordPress site with LWS Optimize?

9mn reading

How do I disable WordPress emojis with LWS Optimize?


Questions sur cet article

Ask the LWS team and its community a question

RGPD : Responsable LWS-Ligne Web Services. Finalité : modération et publication publique de votre question, notification éventuelle d'une réponse. Base légale : consentement (art. 6.1.a RGPD). Conservation des emails : 90 jours après notification, 12 mois maximum sans réponse. Vous pouvez exercer vos droits via notre nos CGV - section RGPD.