PHPackages                             garethellis/crontab-schedule-generator - 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. garethellis/crontab-schedule-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

garethellis/crontab-schedule-generator
======================================

A PHP library for generating crontab schedule strings using expressive code

1.3.0(1y ago)107.6k↓33.3%1[1 issues](https://github.com/garethellis36/crontab-schedule-generator/issues)MITPHPPHP 8.1.\* | 8.2.\* | 8.3.\*

Since Aug 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/garethellis36/crontab-schedule-generator)[ Packagist](https://packagist.org/packages/garethellis/crontab-schedule-generator)[ Docs](https://github.com/garethellis36/crontab-schedule-generator)[ RSS](/packages/garethellis-crontab-schedule-generator/feed)WikiDiscussions master Synced 1mo ago

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

Crontab Schedule Generator
==========================

[](#crontab-schedule-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/34ae2c5d7314b7dcc2da37cab0bbb3dd55d7a936dc94a046742b65df4e0576f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676172657468656c6c69732f63726f6e7461622d7363686564756c652d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/garethellis/crontab-schedule-generator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/88a987cb318bed51852ac83b48871ef37b5347c57ae428c8af0b8a543cd3670d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676172657468656c6c69732f63726f6e7461622d7363686564756c652d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/garethellis/crontab-schedule-generator)

A simple PHP library for generating Crontab schedules with expressive PHP code.

Install
-------

[](#install)

Install with Composer:

```
$ composer require garethellis/crontab-schedule-generator
```

Usage
-----

[](#usage)

I wrote this library for use with [Jobby](https://github.com/jobbyphp/jobby), but it could be used in any situation where you need to output a Crontab schedule with PHP.

I recommend using the included functions for expressive code.

### Hourly

[](#hourly)

The `Hourly` class can be used to output crontab schedules to be run on an hourly basis. The `hourly()` function can be used to create a new instance of `Hourly`.

If you call `hourly()` by itself, you'll get a crontab schedule of "run hourly on the hour". You can specify the minutes past the hour to run at by using the `at()` method. This method takes either a numeric string (0-59) or one of the following text strings: `on the hour`, `quarter past`, `half past` or `quarter to`.

You can use the `repeatingAt` method to run a task multiple times in an hour. This method takes the same argument as `at()`, i.e. a numeric string (0-59) or a text string from the above list.

```
use function Garethellis\CrontabScheduleGenerator\hourly;

echo hourly();
//outputs "0 * * * *" (i.e. run hourly on the hour)

echo hourly()->at("20");
//outputs "20 * * * *" (i.e. run hourly at twenty past the hour)

echo hourly()->at("half past");
//outputs "30 * * * *" (i.e. run hourly at half past the hour)

echo hourly()->at("on the hour")->repeatingAt("quarter past")->repeatingAt("half past")->repeatingAt("quarter to");
//outputs "0,15,30,45 * * * *" (i.e. run every 15 minutes)
```

### Daily

[](#daily)

The `Daily` class can be used to output crontab schedules to be run on a daily basis. The `daily()` function returns a new instance of `Daily`.

If you call `daily()` by itself, you will get a crontab schedule of "run daily at midnight". You can specify a time to run using the `at()` method. This method takes a (string) time in 24 hour format as its only argument (e.g. `"16:00"`).

There is also the `repeatingAt()` method if you would like to schedule a task to run multiple times in a day. This method takes a whole number (numeric string) as its only argument; this number represents the hour to repeat the job at. Note, this will create a schedule which repeats at the same number of minutes past the hour as whatever you specify using the `at()` method. It's not possible (currently) to do something like "run at 9:30, then repeat at 11:15, then repeat at "13:40".

```
use function Garethellis\CrontabScheduleGenerator\daily;

echo daily();
//outputs "0 0 * * *" (i.e. run daily at midnight)

echo daily()->at("4");
//outputs "0 4 * * *" (i.e. run daily at 4am)

echo daily()->at("15:25");
//outputs "25 15 * * *" (i.e. run daily at 3:25pm / 15:25)

echo daily()->at("9:30")->repeatingAt("10")->repeatingAt("11");
//outputs "30 9,10,11 * * *" (i.e. run daily at 9:30, 10:30 and 11:30)
```

### Weekly

[](#weekly)

The `Weekly` class can be used to output crontab schedules to be run on a daily basis. The `weekly()` function returns a new instance of `Weekly`.

If you call `weekly()` by itself, you will get a crontab schedule for midnight Sunday. You can specify a day to run on using the `on()` method. This method takes a day name in English (e.g. 'Sunday') as its only argument. If you call it like this, you will get a crontab schedule set to run on that given day at midnight. You can specify a time to run in the same way as the `Daily` class - see above.

You can also set weekly schedules to repeat on given days using the `repeatingOn()` method, passing in a day name.

```
use function Garethellis\CrontabScheduleGenerator\weekly;

echo weekly();
//outputs "0 0 * * 0"

echo weekly()->on("Friday");
//outputs "0 0 * * 4" (i.e. run every Friday at midnight)

echo weekly()->on("Saturday")->at("12:10");
//outputs "10 12 * * 6" (i.e. run every Saturday at 12:10pm

echo weekly()->on("Saturday")->repeatingOn("Sunday");
//outputs "0 0 * * 0,6" (i.e. run every Saturday & Sunday at midnight)
```

### Monthly

[](#monthly)

The `Monthly` class allows you to output crontab schedules to be run on a monthly basis. The `monthly()` function returns a new instance of `Monthly`.

Calling `monthly()` by itself will give you a crontab schedule for midnight on the first of the month. To specify a day to run on, you can use an ordinal or whole number (as a numeric string) with the `on()` method. You can also use the `at()` method in the same way as with weekly &amp; daily.

```
use function Garethellis\CrontabScheduleGenerator\monthly;

echo monthly();
//outputs "0 0 1 * *"

echo monthly()->on("4th");
//outputs "0 0 4 * *" (i.e. run every month on the 4th at midnight)

echo monthly()->on("12th")->at("10:15");
//outputs "15 10 12 * *" (i.e. run every month on the 12th at 10:15am)
```

### Every X minutes/Every X hours

[](#every-x-minutesevery-x-hours)

The `Interval` class allows you to output crontab schedules to be run every X minutes or every X hours. This class can be instantiated using the factory function `every()`. Unlike the other classes in this library, this class is no good on its own, i.e. `every("5")` will not output anything. Instead, you have to use the `minutes()` and `hours()`methods to create instances of `MinutesInterval` and `HoursInterval` respectively. From here, usage of these classes is very similar to the above. With `HoursInterval` you can specify a start and stop time using the `from()` and `until()` methods.

For `MinutesInterval`, the interval value must be a divisor of 60 as a numeric string (i.e. 1,2,3,4,5,6,10,12,15,20,30,60).

```
use function Garethellis\CrontabScheduleGenerator\every`

echo every("5")->minutes();
//outputs "*/5 * * * *" (i.e. run every 5 minutes)

echo every("2")->hours();
//outputs "0 */2 * * *" (i.e. run every 2 hours on the hour)

echo every("3")->hours()->at("half past");
//outputs "30 */3 * * *" (i.e. run every 3 hours at half past the hour)

echo every("2")->hours()->from("8")->until("14");
//outputs "0 8,10,12,14 * * *" (i.e. run on the hour at 8am, 10am, 12pm and 2pm)
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ vendor/bin/phpunit
```

Code Style
----------

[](#code-style)

Easily check the code style against [PSR-12 Coding Standard](https://www.php-fig.org/psr/psr-12) by running:

```
$ vendor/bin/phpcs src/ --standard=PSR12 --report=summary
```

And automatically fix them with this:

```
$ vendor/bin/phpcbf src/ --standard=PSR12
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Gareth Ellis](https://github.com/garethellis36)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~203 days

Recently: every ~305 days

Total

15

Last Release

689d ago

Major Versions

0.7 → 1.0.02021-02-17

PHP version history (4 changes)0.1PHP ^5.6|^7.0

1.0.0PHP 7.3.\* | 7.4.\* | 8.0.\*

1.2.0PHP 7.3.\* | 7.4.\* | 8.0.\* | 8.1.\*

1.3.0PHP 8.1.\* | 8.2.\* | 8.3.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/c0e7c90d5ab368a89e7413b9298bbfcf5ac16e6adc8eb3abe2569914be0b0a3e?d=identicon)[Garethellis](/maintainers/Garethellis)

---

Top Contributors

[![garethellis36](https://avatars.githubusercontent.com/u/6451455?v=4)](https://github.com/garethellis36 "garethellis36 (15 commits)")

---

Tags

crontab

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/garethellis-crontab-schedule-generator/health.svg)

```
[![Health](https://phpackages.com/badges/garethellis-crontab-schedule-generator/health.svg)](https://phpackages.com/packages/garethellis-crontab-schedule-generator)
```

###  Alternatives

[mult1mate/cron-manager

Flexible cron tasks manager for MVC-type applications

40338.5k3](/packages/mult1mate-cron-manager)[workerman/crontab

A crontab written in PHP based on workerman

70164.2k58](/packages/workerman-crontab)[hyperf/crontab

A crontab component for Hyperf.

131.6M62](/packages/hyperf-crontab)[yzh52521/webman-task

 dynamic crontab task plugin for webman.

171.9k2](/packages/yzh52521-webman-task)

PHPackages © 2026

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