steinm6/cron-helper
Composer 安装命令:
composer require steinm6/cron-helper
包简介
Simple helper to prevent parallel cronjob execution
README 文档
README
Simple helper to prevent parallel cronjob execution
Installation
Composer
Require "steinm6/cron-helper": "dev-master"
Manually
Just include the file src/CronHelper.php
Usage
Initialize the CronHelper with a filename. The CronHelper will use this filename for locking up.
$cron = new CronHelper('myfilename');
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.
Here is a basic example on how to use the CronHelper:
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(); }
统计信息
- 总下载量: 97
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-10-17