Shopware - Disable Admin Worker in Shopware 6
In this article, you will learn how to disable the Admin Worker in Shopware 6 and manage the message queue using the CLI Worker instead.
Please note: The following description applies to the current Shopware version 6.6. For version 6.4 or older versions, please check the official Shopware documentation.
In Shopware 6, the so-called Admin Worker, which performs tasks asynchronously in the background, is enabled by default. These tasks are located in the message queue and are triggered when a user is logged into the Shopware admin.
However, with a large number of users logged into the Shopware Admin, the CPU load can increase to such an extent that the execution of the tasks is disrupted. In addition, no tasks are executed if there is no logged-in user in Shopware Admin. This can, for example, affect tasks that are to be performed at night.
The official recommendation from Shopware is therefore to disable the Admin Worker and use the CLI Worker instead to process the message queue. There are several options available for the setup. One possible approach is to call the message queue via a cronjob. Alternatively, it can be invoked via a process management service such as Supervisor or Systemd.
Disabling the Admin Worker
To disable the Admin Worker, the following configuration must be added to the config/packages/shopware.yaml file:shopware: admin_worker: enable_admin_worker: false
After the admin worker has been disabled, the processes scheduled-task:run as well as messenger:consume have to be started.
For this purpose we present three different possibilities in the following:
Calling the Message Queue via Cronjob
To run the Consumer and Scheduled Task processes using cronjobs, enter the following lines in your crontab list:
* * * * * /usr/bin/php /var/www/share/demoshop.com/shopware/bin/console scheduled-task:run --no-wait
*/3 * * * * /usr/bin/php /var/www/share/demoshop.com/shopware/bin/console messenger:consume async --time-limit=120
This will automatically run both processes every three minutes. The runtime of both processes is two minutes each. The runtimes are to ensure that the processes are not started multiple times in parallel. Shopware recommends the setting of a short runtime to avoid memory leaks with long running PHP processes.
Note: Prior to Shopware version 6.5.5.0, you must use --time-limit=120 instead of the --no-wait parameter.
Calling the message queue via Supervisor
Note: If you access the message queue via Supervisor, Supervisor must be installed in Managed Center.
To manage the processes using Supervisor, you can use the following configuration templates for the Consumer as well as the Scheduled Task. If the process is terminated by the time limit, Supervisor will restart it. Via numprocs you can define how many processes should be started at the same time. Usually one process is sufficient. Only in the case of very large instances or many tasks is it worth increasing the number.
Consumer[program:messenger-consumer]command=php /var/www/share/demoshop.com/shopware6/bin/console messenger:consume --time-limit=3600numprocs=1autostart=trueautorestart=trueprocess_name=%(program_name)s_%(process_num)02d
Scheduled Task[program:scheduled-task]command=php /var/www/share/demoshop.com/shopware6/bin/console scheduled-task:run --time-limit=3600numprocs=1autostart=trueautorestart=trueprocess_name=%(program_name)s_%(process_num)02d
Note: The scheduled task command can also run as cron job. For more information, visit https://developer.shopware.com/docs/guides/hosting/infrastructure/scheduled-task.html#running-scheduled-tasks
If you would like to learn more about our Shopware hosting, you can find all the information you need at maxcluster.de/en/shopware-hosting
If you require any further assistance, please contact our support team by phone at +49 5251/414130 or by email at support@maxcluster.de