Forge Queue Workers Explained
This guest post authored by Mohamed Said.
Laravel ships with a powerful background job processing system, ensuring your users receive quick responses to their HTTP requests.
To process jobs from the queue, a “worker” process runs on your server and is responsible for processing any jobs on the queue. A process monitor such as Supervisor is typically used to make sure the workers are always running. Configuring Supervisor can be overwhelming; however, Forge can easily configure Supervisor through a convenient UI.
After signing into your Forge dashboard, select a site that requires a worker process. Then, select the “Queues” link on the side menu. When creating a new worker, you should specify the “connection” and “queue” the worker should process jobs from. The “connection” corresponds to one of the connection entires in your Laravel application’s
queue.php configuration file. The "queue" corresponds to the names of the queues on which the worker should inspect for jobs. If multiple queues are required, you may specify a comma-delimited list in this field. Queues listed earlier in the list will be checked first for jobs before the worker moves on to subsequent queues.
In addition to the connection and queue, you may also define the following configuration options:
Rest Seconds When Empty
This configuration option defines the number of seconds the worker will sleep if no jobs are available on the queue.
This configuration option defines the number of worker instances Forge should create. For example, if “2” is specified for this option, Forge will create two worker instances and therefore will be able to process multiple jobs at the same time.
This configuration option defines the number of times a job will be retried in case of failure. If the job fails to complete within the specified number of tries, the job will be inserted into your application’s
This configuration option allows you to define a
--env flag for the
queue:work command generated by Forge.
This configuration option instructs Forge to use long-running processes to process jobs. Otherwise, Laravel will reload the entire application for each job it processes. Since this option provides a great reduction in CPU and RAM usage, it should almost always be selected unless you have an explicit need to reload the framework before processing each job.
To get started using Forge, sign up today.