2017 © Pedro Peláez
 

library cron-helper

Simple helper to prevent parallel cronjob execution

image

steinm6/cron-helper

Simple helper to prevent parallel cronjob execution

  • Tuesday, December 16, 2014
  • by steinm
  • Repository
  • 2 Watchers
  • 1 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

cron-helper

Simple helper to prevent parallel cronjob execution, (*1)

Installation

Composer

Require "steinm6/cron-helper": "dev-master", (*2)

Manually

Just include the file src/CronHelper.php, (*3)

Usage

Initialize the CronHelper with a filename. The CronHelper will use this filename for locking up., (*4)

$cron = new CronHelper('myfilename');, (*5)

To lock the execution call the lock()-function. To unlock the cronjob use the unlock()-function. You may determine how long the cronjob was locked by calling the getLockDuration()-function, which returns the time passed since the lock() in seconds., (*6)

Here is a basic example on how to use the CronHelper:, (*7)

use steinm6\CronHelper\CronHelper;

// Initialize CronHelper
$cron = new CronHelper('lockfile-name');

// lock this job
if ($cron->lock()) {
    foreach($x as $y){
        // You might want to reset the timer, to prevent running into the unlock() below...
        $cron->resetTimer();

        // Do something
        sleep(10);
    }
    $cron->unlock();
} else {
  // If the lock persists for 3600 seconds, something went wrong. Remove the lock so that the next cronjob is executed.
    if ($cron->getLockDuration() > 3600)
        $cron->unlock();
}

The Versions

16/12 2014

dev-master

9999999-dev

Simple helper to prevent parallel cronjob execution

  Sources   Download

BSD-3-Clause

by Matthias Stein

20/10 2014

1.1.0

1.1.0.0

Simple helper to prevent parallel cronjob execution

  Sources   Download

BSD-3-Clause

by Matthias Stein

18/10 2014

1.0.0

1.0.0.0

Simple helper to prevent parallel cronjob execution

  Sources   Download

BSD-3-Clause

by Matthias Stein