PHP code example of steinm6 / cron-helper
1. Go to this page and download the library: Download steinm6/cron-helper library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
steinm6 / cron-helper example snippets
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();
}