0

Is there a way to run these commands:

php -dmemory_limit=12G bin/magento catalog:images:resize -a

or

php -dmemory_limit=12G bin/magento queue:consumer:start media.storage.catalog.image.resize

without having to keep the terminal opened?

The process takes several days as we have 900k images in our store. This requires the terminal window to be opened this whole time. As soon as window is closed, the process stops.

This guide talks about running image resize in async mode, but it still requires the window to be opened on both the resize command and the consumer command.

3

Simple solution – append & to the command for it to detach from the terminal and run in the background. You'd have to monitor its completion using process monitoring tools like ps and may want to redirect its output to a file to watch the progress while it's still running.

php -dmemory_limit=12G bin/magento catalog:images:resize -a &

A more advanced approach is to use screens – the tool allowing to detach from and reattach to terminal sessions running in the background. You won't have to redirect the output to a file.

1

It looks like I might be able to use nohup to do this:

https://linuxhint.com/how_to_use_nohup_linux/

Something like this:

nohup bash -c 'php -dmemory_limit=10G bin/magento catalog:images:resize -a && php -dmemory_limit=10G bin/magento queue:consumer:start media.storage.catalog.image.resize'> var/log/image-resize.txt

UPDATE: so far the commands are running fine and much faster than synchronous command.

Within 30 minutes the process is up to 4%.

1

Your best option is to make use of the Linux tool "screen". You might need to install it though. It might not be part of the default Linux installation.

To start a new screen session, simply run the command: screen

Now you are able to launch any program that you want. To exit the screen session type: CRTL+A CRTL+D

This will get you back to your initial shell. The program you launched in the screen session will run in the background. If you are logged in to a remote server you can also log off and the program will keep running in the screen session until it's done. The screen session will be kept open until you exit it.

If you want to reconnect to your screen session type: screen -r

To exit / close the screen session and get back to your initial shell type: exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.