Download the PHP package facile-it/terminable-loop-command without Composer

On this page you can find all versions of the php package facile-it/terminable-loop-command. 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 terminable-loop-command

facile-it/terminable-loop-command

Latest Stable Version Build status Coverage status

A Shell+PHP combination to run Symfony console commands in loop under a daemon or Kubernetes, instead of using a long running process.

This package contains a shell script and an abstract Symfony Console Command class; you need to write your command extending that class, and launch it through the shell script. Ideally, the script has to be used as a container entry point, and/or launched with a supervisor, like Docker Compose, Kubernetes, supervisord.

Installation

Usage

Launch the shell script appending the desired PHP script to be executed in a loop:

... where my_custom_command.php launches your command class, which must extend AbstractTerminableCommand (see the test stub in this repo)

Example with a command in a common Symfony app

When using it inside a Symfony application, do not forget to call bin/console as first argument:

... where the command is something like this:

Why?

When running a PHP application, you may encounter the need of a background command that runs continuously. You can try to write it as a long running process, but it can be prone to memory leaks and other issues.

With this small Shell+PHP combination, you can have a simple loop that:

The shell script intercepts SIGTERM/SIGINT signals so, when they are received, the PHP script is stopped ASAP but gracefully, since the execution of the body of the command is never truncated.

This means that you can easily obtain a daemon PHP script without running in memory issues; if you run this in a Kubernetes environment this will be very powerful, since the orchestrator will take care of running the script, and at the same time it will apply the proper restart policies in case of crashes. Last but not least, the signal handling will play nice with shutdown requests, like during the roll out of a new deployment.

How it works

The shell script is pretty basic, calling the desired command in a loop, until it exits with an exit code different than 0; it also traps SIGTERM/SIGKILL signals and forwards them to the PHP process.

The PHP Command is designed to first execute a main task (the AbstractTerminableCommand::commandBody() function) and afterwards sleep for a custom amount of time, which can be customized at any time during the command execution; this is powerful since you can let your command logic decide how much to wait between two command executions, even nothing.

The PHP class also gracefully handles the signals, which means that if the signal is received during the commandBody() function, it will wait for its conclusion; if it's received during the sleep phase, it will terminate it immediately. In case of termination due to signal, the command exits with and exit code of 143, which means exactly that we're exiting due to the signal: this will interrupt the shell script loop execution, without being considered as an error from the point of view of the supervising agent, like Kubernetes.


All versions of terminable-loop-command with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 | ^8.0
ext-pcntl Version *
symfony/console Version ^4.4 | ^5.4 | ^6.0 | ^7.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 facile-it/terminable-loop-command contains the following files

Loading the files please wait ....