PHPackages                             boboldehampsink/cronjob - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. boboldehampsink/cronjob

AbandonedArchivedCraft-plugin[Utility &amp; Helpers](/categories/utility)

boboldehampsink/cronjob
=======================

Cronjob Manager plugin for Craft CMS

0.1.1(9y ago)233.0k2[3 issues](https://github.com/boboldehampsink/cronjob/issues)PHP

Since Jul 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/boboldehampsink/cronjob)[ Packagist](https://packagist.org/packages/boboldehampsink/cronjob)[ RSS](/packages/boboldehampsink-cronjob/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (0)

DEPRECATED - Cronjob Manager plugin for Craft CMS
=================================================

[](#deprecated---cronjob-manager-plugin-for-craft-cms)

Craft plugin to programmatically manage GNU/Linux cronjobs.

Deprecated:
-----------

[](#deprecated)

With the release of Craft 3 on 4-4-2018, this plugin has been deprecated. You can still use this with Craft 2 but you are encouraged to use (and develop) a Craft 3 version. At this moment, I have no plans to do so.

Features:
---------

[](#features)

- Deal with your cronjobs in Craft.
- Create new cronjobs.
- Update existing cronjobs.
- Manage cronjobs of others users than runtime user using some sudo tricks (see below).

Requirements:
-------------

[](#requirements)

- `crontab` command-line utility (should be already installed in your distribution).
- `sudo`, if you want to manage crontab of another user than runtime user without running into right issues (see below)

Installation:
-------------

[](#installation)

The library can be installed using Composer.

```
composer require boboldehampsink/cronjob

```

Usage:
------

[](#usage)

The plugin is composed of three models:

- `CronjobModel` is an entity model which represent a cronjob.
- `Cronjob_RepositoryModel` is used to persist/retrieve your jobs.
- `Cronjob_AdapterModel` abstracts raw crontab read/write.

### Instanciate the repository:

[](#instanciate-the-repository)

In order to work, the `Cronjob_RepositoryModel` needs an instance of `Cronjob_AdapterModel` which handles raw read/write against the crontab.

```
$crontabRepository = new Cronjob_RepositoryModel(new Cronjob_AdapterModel());
```

### Create a new cronjob and persist it into the crontab:

[](#create-a-new-cronjob-and-persist-it-into-the-crontab)

Suppose you want to create an new job which consist of launching the command "df &gt;&gt; /tmp/df.log" every day at 23:30. You can do it in two ways.

- In pure OO way:

```
$cronjob = new CronjobModel();
$cronjob->minutes = '30';
$cronjob->hours = '23';
$cronjob->dayOfMonth = '*';
$cronjob->months = '*';
$cronjob->dayOfWeek = '*';
$cronjob->taskCommandLine = 'df >> /tmp/df.log';
$cronjob->comments = 'Logging disk usage'; // Comments are persisted in the crontab
```

- From raw cron syntax string using a factory method:

```
$cronjob = CronjobModel::createFromCrontabLine('30 23 * * * df >> /tmp/df.log');
```

You can now add your new cronjob in the crontab repository and persist all changes to the crontab.

```
$crontabAdapter = new Cronjob_AdapterModel();
$crontabRepository = new Cronjob_RepositoryModel($crontabAdapter);
$crontabRepository->addJob($cronjob);
$crontabRepository->persist();
```

### Find a specific cronjob from the crontab repository and update it:

[](#find-a-specific-cronjob-from-the-crontab-repository-and-update-it)

Suppose we want to modify the hour of an already existing cronjob. Finding existings jobs is made using some regular expressions. Search in made against the entire crontab line.

```
$results = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');
$cronjob = $results[0];
$cronjob->hours = '21';
$crontabRepository->persist();
```

### Remove a cronjob from the crontab:

[](#remove-a-cronjob-from-the-crontab)

You can remove a job like this :

```
$results = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');
$cronjob = $results[0];
$crontabRepository->removeJob($cronjob);
$crontabRepository->persist();
```

Note: Since cronjobs are internally matched by reference, they must be previously obtained from the repository or previously added.

### Work with the crontab of another user than runtime user:

[](#work-with-the-crontab-of-another-user-than-runtime-user)

This feature allow you to manage the crontab of another user than the user who launched the runtime. This can be useful when the runtime user is `www-data` but the owner of the crontab you want to edit is your own linux user account.

To do this, simply pass the username of the crontab owner as parameter of the `Cronjob_AdapterModel` constructor. Suppose you are `www-data` and you want to edit the crontab of user `bobby`:

```
$crontabAdapter = new Cronjob_AdapterModel('bobby');
$crontabRepository = new Cronjob_RepositoryModel($crontabAdapter);
```

Using this way you will propably run into user rights issue. This can be resolved by editing your sudoers file using 'visudo'.
If you want to allow user `www-data` to edit the crontab of user `bobby`, add this line:

```
www-data        ALL=(bobby) NOPASSWD: /usr/bin/crontab

```

which tells sudo to not ask for password when you call `crontab` of user `bobby`

Now, you can have access to the crontab of user `bobby` like this :

```
$crontabAdapter = new Cronjob_AdapterModel('bobby', true);
$crontabRepository = new Cronjob_RepositoryModel($crontabAdapter);
```

Note the second parameter `true` of the `Cronjob_AdapterModel` constructor call. This boolean tell the `Cronjob_AdapterModel` to use 'sudo' internally to read/write the crontab.

### Enable or disable a cronjob

[](#enable-or-disable-a-cronjob)

You can enable or disable your cron jobs by setting the "enabled" attribute of a `CronjobModel` object accordingly:

```
$crontabJob->enabled = false;
```

This will have the effect to prepend your cronjob by a "#" in your crontab when persisting it.

Todo
----

[](#todo)

- Create ElementType to manage cronjobs from the CP

Changelog
---------

[](#changelog)

### 0.1.1

[](#011)

- Updated dependencies

### 0.1.0

[](#010)

- Initial release that allows you to manage cronjobs programmatically

Credits
-------

[](#credits)

Based on [TiBeN/CrontabManager](https://github.com/TiBeN/CrontabManager)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~677 days

Total

2

Last Release

3290d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3dd0df0464b4919048281ee42a9210f4323e8f3a78d046067e550992e4a5fb7e?d=identicon)[boboldehampsink](/maintainers/boboldehampsink)

### Embed Badge

![Health badge](/badges/boboldehampsink-cronjob/health.svg)

```
[![Health](https://phpackages.com/badges/boboldehampsink-cronjob/health.svg)](https://phpackages.com/packages/boboldehampsink-cronjob)
```

###  Alternatives

[rainlab/blog-plugin

Blog plugin for October CMS

17257.7k](/packages/rainlab-blog-plugin)[rainlab/builder-plugin

Builder plugin for October CMS

17147.2k1](/packages/rainlab-builder-plugin)[pfefferle/wordpress-activitypub

The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.

5671.4k1](/packages/pfefferle-wordpress-activitypub)[civicrm/civicrm-drupal-8

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

18238.1k2](/packages/civicrm-civicrm-drupal-8)[mediawiki/semantic-glossary

A terminology markup extension with a Semantic MediaWiki back-end

1352.4k](/packages/mediawiki-semantic-glossary)[humanmade/lottie-lite

A lightweight Lottie Animations Extension for WordPress

374.3k](/packages/humanmade-lottie-lite)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
