Download the PHP package hammerstone/laravel-pseudo-daemon without Composer

On this page you can find all versions of the php package hammerstone/laravel-pseudo-daemon. 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 laravel-pseudo-daemon

🚨🚨 Do not use

You should probably use the framework's built-in sub-minute scheduled tasks now instead of this package. I'll mark it as abandoned at some point!

Laravel Pseudo-Daemons

A Laravel package to mimic daemons via scheduled commands without having to change server configuration.

For more information / rationale, see https://aaronfrancis.com/2020/laravel-pseudo-daemons.

Installation

You can install the package via composer:

composer require Hammerstone/laravel-pseudo-daemon

Basic Usage

Add the IsPseudoDaemon trait to any of your Laravel Commands and call runAsPseudoDaemon from the handle method.

Then, in your Console\Kernel, run your command with the daemonize modifier. This is a macro that sets it to run every minute, in the background, without overlapping.

The process method will be kept alive for as long as you want, all controlled by your code without any Supervisor configuration, and without having to change your deploy scripts to kill it.

Stopping the Daemon

Obviously there are going to be times you need to kill your daemon so that the scheduler can restart it. The most obvious time is when deploying new code, but there are plenty of other reasons to kill it off, and several ways to do so.

Restart After Number Of Times Run

If you'd like to stop the daemon after it runs a certain number of times, you can override the restartAfterNumberOfTimesRun() method. By default, it returns 1000 in production and 1 otherwise.

Restart After Minutes

To set a maximum runtime in minutes, override restartAfterMinutes(). By default the daemons all run for 60 minutes.

Restart When Something Arbitrary Changes

You'll want to kill your daemons when you deploy new code, which is easy enough with the restartWhenChanged() method. You can return any data you want from this method, and if it ever changes the daemon will stop.

Forge + Envoyer

If you're using on Laravel Forge with Envoyer, the trait will automatically handle stopping itself whenever you deploy fresh code. You don't have to do a single thing! The trait will read the real path of the current symlink that Envoyer creates. Anytime that changes the daemon will stop.

Other Hosting

If you're not on Forge with Envoyer, you can extend the restartWhenChanged() method and return whatever you want. You can read a git hash, a build time, or do anything else. Anytime we detect that the data is different, the loop breaks.

Here's an example that reads the current git hash:

Stopping Whenever You Want

If you'd like to initiate a stop from inside your process method, you may return PseudoDaemonControl::STOP and the daemon will not run any more iterations.

Sleeping

So that your daemon doesn't run thousands of times per minute when there is nothing to do, we default to sleeping 7 seconds between iterations. If you'd like to change that amount you may override pseudoDaemonSleepSeconds().

If you'd like to explicitly not sleep on a certain iteration, you may return PseudoDaemonControl::DONT_SLEEP from your process method.

Running Code Before / After

If you'd like to do some setup and/or cleanup outside of the main loop, beforePseudoDaemonRun() and beforePseudoDaemonShutdown() are both available to you.


All versions of laravel-pseudo-daemon with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ^8.0|^9.0|^10.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 hammerstone/laravel-pseudo-daemon contains the following files

Loading the files please wait ....