Download the PHP package mehr-it/lara-worker-heartbeat without Composer

On this page you can find all versions of the php package mehr-it/lara-worker-heartbeat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lara-worker-heartbeat

Queue worker heartbeat for Laravel

This package implements a queue worker heartbeat which is observed by another process to detect stuck or hanging queue worker processes.

Why is a heartbeat necessary?

Laravel has a built in timeout handling for worker processes which uses SIGALRM to let worker processes terminate themselves when they reach a given timeout. However this cannot handle edge cases when the whole process is stuck in a way that signals are not processed anymore or the worker gets stuck before the signal handler was registered.

Even supervisord is of no help in such cases because the worker process might still be running, but not doing anything anymore.

How does it work?

This package extends the queue:work command by the ability to fork an observer process which monitors an implemented worker heartbeat. Laravel's queue worker is extended to send regular heartbeat signals and status information to the observer process. When the observer process does not receive a heartbeat signal within the expected period, it will kill the worker process.

Installation

composer require mehr-it/lara-worker-heartbeat

This package uses Laravel's package auto-discovery, so the service provider will be loaded automatically.

Make sure the PHP extensions posix and pcntl are loaded. Otherwise queue workers cannot fork the required observer process and will throw an error.

Usage

You don't have to make any changes to your application code to use this package. You only have to pass the --heartbeat-timeout option to the queue work command:

artisan queue:work default --heartbeat-timeout=5

This will start an observer thread expecting a heartbeat signal within every 5 seconds. Of course no heartbeat is expected while the worker process is sleeping or handling a job taking longer than 5s.

Choose the heartbeat timeout depending on the expected worker cycle duration (without any sleep time). Usually this is a little more than the time it takes to query the queue for new jobs. So most of the time 5s is a safe value. But in cases when the pop operation takes longer (eg. when using AWS SQS with long polling) you have to increase the timeout.

Implementation details

Heartbeat signals are sent on each iteration of the worker loop, which is looking for new jobs in the queue.

When the worker is going to sleep or starts processing a job, it does not send any heartbeat signals for some time. The worker will notify the observer about the period it will not be able to send any heartbeat and the observer will respect that.

If neither a timeout is set for the worker process nor for the currently processed job, the observer process does expect any heartbeat until the job is finished. In this situation the observer cannot detect hung or stuck processes, because it does not know when to expect the next heartbeat signal.

The observer process automatically stops when the observed worker process is not running anymore.


All versions of lara-worker-heartbeat with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
laravel/framework Version ^6.0|^7.0|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mehr-it/lara-worker-heartbeat contains the following files

Loading the files please wait ....