How to run WP-CLI in the background
If you have a lot of images to resize, you can run WP-CLI in the background so you don't need to wait for the process to finish. In this quick guide, I'll show you how you can run the command
wp media regenerate
in the background:- 1.
- 2.Open your server terminal
- 3.Type the command
nohup wp media regenerate --yes
followed by&
$ nohup wp media regenerate --yes &
This will run regeneration in the background and print the process identifier number of the job:
[1] 22699
To view regenerated thumbnails log, type:
$ cat nohup.out
To list running jobs, type the command
jobs
$ jobs
The output will be similar to this:
[1]+ Running nohup wp media regenerate --yes &
To stop regeneration, use the command
kill
and the job number in [1]+
$ kill %1
Note: If you ended the terminal session, you will need to use the command
ps -eaf | grep wp
instead of jobs
to list running jobs:ps -eaf | grep wp
The output will be similar to:
501 22699 22389 0 3:19PM ttys000 0:00.14 wp media regenerate --yes
To terminate the job process, use the identifier number to terminate it:
kill 22699