Download the PHP package incapption/load-balanced-cron-task without Composer

On this page you can find all versions of the php package incapption/load-balanced-cron-task. 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 load-balanced-cron-task

Load Balanced Cron Task

Introduction

This is a lightweight package for load balancing your cron tasks. It is used to distribute tasks across a network of identical servers to make sure they are run only once and not multiple times.

It is important that your application network uses only one single central mysql database. A table is created in the database in which current tasks are inserted. A primary key ensures that the task only runs once (a kind of locking process).

the unique_hash is a md5 hash of the task name, the schedule and the current timestamp without seconds. With this, the nodes can run asynchronously but the task runs only once at a time.


Scheme of operation

Requirements

1. Installation

1.1 Composer

Install Load Balanced Cron Task using Composer.

1.2 Create MySQL Table

This package needs a small table in your database. It's used for locking running tasks, to make sure that only on app instance could run it.

1.3 Install Crontab

The idea is that you have only one single cron task running every minute. This cron task contains all other tasks wrapped by LoadBalancedCronTask

Open your crontab console (e.g. linux: )

1.4 Create your cron file

Maybe you want to integrate into your application, or you create a new plain file.


2. How to use it

As shown in the example above you need to create classes for your cron tasks that extends CronTaskAbstract. Define the behavior in the task() method.

Second create the load balanced cron task.

2.1 Chainable methods

General:

Method Description
->mysql(string $host, string $user, string $password, string $database) Sets the mysql credentials for the underlying pdo instance
->setWorkerName(string $name) Sets the name of the current worker. Perhaps you will use a environment variable
->task(CronTaskAbstract $task) Awaits an instance of CronTaskAbstract
->local() Sets the cron task to local. No distributing and load balancing is taking place. Useful for node specific tasks such as cleaning local tmp folder etc.
->loadBalanced() Sets the cron task to load balanced. The task is distributed around the network. Only one worker runs the task at a time.

Scheduling methods:

Method Description
->everyMinute() Run the task every minute
->everyTwoMinutes() Run the task every two minutes
->everyThreeMinutes() Run the task every three minutes
->everyTenMinutes() Run the task every five minutes
->everyFifteenMinutes() Run the task every fifteen minutes
->everyThirtyMinutes() Run the task every thirty minutes
->hourly() Run the task every hour
->hourlyAt(17) Run the task every hour at 17 minutes past the hour
->daily() Run the task every day at 00:00
->dailyAt('17:13') Run the task every day at 17:13 o'clock
->monthly() Run the task on the first day of every month at 00:00
->monthlyOn(4, '15:00') Run the task every month on the 4th at 15:00
->lastDayOfMonth('15:00') Run the task on the last day of the month at 15:00
->lastDayOfMonthOffset(2, '15:00') Run the task on the last day of the month at 15:00 with an offset of 2 days. As an example: lastDayOfMonthOffset(2, '15:00') in january, which has 31 days, runs on the 29th at 15 o'clock

Be careful with the days 29th, 30th, 31st if you use monthlyOn(). Maybe use lastDayOfMonth() or lastDayOfMonthOffset() instead.


3. Exceptions

An instance of LoadBalancedCronTask() throws a LoadBalancedCronTaskException when there is something wrong inside the logic for everything else you can use the default PHP Exceptions.


All versions of load-balanced-cron-task with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
myclabs/php-enum Version ^1.8
ext-json Version *
ext-pdo Version *
ext-pdo_mysql Version *
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 incapption/load-balanced-cron-task contains the following files

Loading the files please wait ....