Manage all your cron jobs without modifying crontab. Handles locking, logging, error emails, and more.

Related tags

Task Runners jobby
Overview

Jobby, a PHP cron job manager

Total Downloads Latest Version Build Status MIT License

Install the master jobby cron job, and it will manage all your offline tasks. Add jobs without modifying crontab. Jobby can handle logging, locking, error emails and more.

NEW REPO: We have moved jobby to a Github org. Please update your remotes to https://github.com/jobbyphp/jobby.git.

Features

  • Maintain one master crontab job.
  • Jobs run via PHP, so you can run them under any programmatic conditions.
  • Use ordinary crontab schedule syntax (powered by the excellent cron-expression).
  • Run only one copy of a job at a given time.
  • Send email whenever a job exits with an error status.
  • Run job as another user, if crontab user has sudo privileges.
  • Run only on certain hostnames (handy in webfarms).
  • Theoretical Windows support (but not ever tested)

Getting Started

Installation

The recommended way to install Jobby is through Composer:

$ composer require hellogerard/jobby

Then add the following line to your (or whomever's) crontab:

* * * * * cd /path/to/project && php jobby.php 1>> /dev/null 2>&1

After Jobby installs, you can copy an example file to the project root.

$ cp vendor/hellogerard/jobby/resources/jobby.php .

Running a job

<?php 

// Ensure you have included composer's autoloader  
require_once __DIR__ . '/vendor/autoload.php';

// Create a new instance of Jobby
$jobby = new Jobby\Jobby();

// Every job has a name
$jobby->add('CommandExample', [

    // Run a shell command
    'command'  => 'ls',

    // Ordinary crontab schedule format is supported.
    // This schedule runs every hour.
    'schedule' => '0 * * * *',

]);

$jobby->run();

Examples

Logging

<?php

/* ... */

$jobby->add('LoggingExample', [
    
    'command' => 'ls',
    'schedule' => '0 * * * *',
    
    // Stdout and stderr is sent to the specified file
    'output' => 'logs/command.log',

]);

/* ... */

Disabling a command

<?php

/* ... */

$jobby->add('DisabledExample', [
    
    'command' => 'ls',
    'schedule' => '0 * * * *',
    
    // You can turn off a job by setting 'enabled' to false
    'enabled' => false,

]);

/* ... */

Running closures

When running closures, beware that nothing outside of the closure is visible (see #93)!

<?php

/* ... */

$jobby->add('ClosureCommandExample', [
    
     // Use the 'closure' key
     // instead of 'command'
    'closure' => function() {
        echo "I'm a function!\n";
        return true;
    },
    
    'schedule' => '0 * * * *',

]);

/* ... */

Using a DateTime

<?php

/* ... */

$jobby->add('DateTimeExample', [
    
    'command' => 'ls',
    
    // Use a DateTime string in
    // the format Y-m-d H:i:s
    'schedule' => '2017-05-03 17:15:00',

]);

/* ... */

Using a Custom Scheduler

<?php

/* ... */

$jobby->add('Example', [
    
    'command' => 'ls',
    
    // Use any callable that returns
    // a boolean stating whether
    // to run the job or not
    'schedule' => function(DateTimeImmutable $now) {
        // Run on even minutes
        return $now->format('i') % 2 === 0;
    },

]);

/* ... */

Supported Options

Each job requires these:

Key Type Description
schedule string Crontab schedule format (man -s 5 crontab) or DateTime format (Y-m-d H:i:s) or callable (function(): Bool { /* ... */ })
command string The shell command to run (exclusive-or with closure)
closure Closure The anonymous PHP function to run (exclusive-or with command)

The options listed below can be applied to an individual job or globally through the Jobby constructor. Global options will be used as default values, and individual jobs can override them.

Option Type Default Description
runAs string null Run as this user, if crontab user has sudo privileges
debug boolean false Send jobby internal messages to 'debug.log'
Filtering Options to determine whether the job should run or not
environment string null or getenv('APPLICATION_ENV') Development environment for this job
runOnHost string gethostname() Run jobs only on this hostname
maxRuntime integer null Maximum execution time for this job (in seconds)
enabled boolean true Run this job at scheduled times
haltDir string null A job will not run if this directory contains a file bearing the job's name
Logging Options for logging
output string /dev/null Redirect stdout and stderr to this file
output_stdout string value from output option Redirect stdout to this file
output_stderr string value from output option Redirect stderr to this file
dateFormat string Y-m-d H:i:s Format for dates on jobby log messages
Mailing Options for emailing errors
recipients string null Comma-separated string of email addresses
mailer string sendmail Email method: sendmail or smtp or mail
smtpHost string null SMTP host, if mailer is smtp
smtpPort integer 25 SMTP port, if mailer is smtp
smtpUsername string null SMTP user, if mailer is smtp
smtpPassword string null SMTP password, if mailer is smtp
smtpSecurity string null SMTP security option: ssl or tls, if mailer is smtp
smtpSender string jobby@<hostname> The sender and from addresses used in SMTP notices
smtpSenderName string Jobby The name used in the from field for SMTP messages

Symfony integration

Symfony bundle for Jobby - imper86/jobby-cron-bundle

Credits

Developed before, but since inspired by whenever.

Support this project

Comments
  • Cronjob not being added.

    Cronjob not being added.

    Here are my current settings. The "hello." is getting echoed out, so I know the code works and everything. I even did a "is_class()" on it.

    screen shot 2014-02-22 at 11 15 25 pm

    Oh, and when I ran the default jobby.php file, it crashed my server and all of my processes went into "D" state.

    What's up with that? Do I need something on my server configured?

    opened by averybross 33
  • Updating 2.2.0 to 3.x.x

    Updating 2.2.0 to 3.x.x

    I'm running into the following issue updating to either 3.0.0 or 3.0.1:

    Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Can only install one of: jeremeamia/SuperClosure[2.2.0, 2.1.0]. - Can only install one of: jeremeamia/SuperClosure[2.2.0, 2.1.0]. - Can only install one of: jeremeamia/SuperClosure[2.2.0, 2.1.0]. - hellogerard/jobby v3.0.1 requires jeremeamia/superclosure ^2.2 -> satisfiable by jeremeamia/SuperClosure[2.2.0]. - Installation request for hellogerard/jobby v3.0.1 -> satisfiable by hellogerard/jobby[v3.0.1]. - Installation request for jeremeamia/superclosure == 2.1.0.0 -> satisfiable by jeremeamia/SuperClosure[2.1.0].

    opened by dyelton 10
  • Class 'Jobby' not found

    Class 'Jobby' not found

    PHP Fatal error: Class 'Jobby' not found in /home/mydir/public_html/jobby.php on line 11

    I have been getting this error repeatedly. I have reinstalled jobby and followed the instructions line by line.

    My root is public_html and my server is cpanel.

    opened by seanspeedymaui 9
  • Protected -> Private - Why?

    Protected -> Private - Why?

    Why were methods changed to private? This only makes Jobby less extendable. I have a couple cases where I've overridden some methods and 2.1 breaks this.

    opened by CarsonF 8
  • Several Things

    Several Things

    • PSR-4 autoloading
    • PSR-2 Code styling, short array syntax, and single quotes
    • Composer
      • Updated dependencies to allow minor releases
      • Removed composer.lock (It's not needed for libraries and general practice is to ignore it.)
    • Travis
      • Updated to builtin composer and caching vendor dirs (should be faster now)
      • Added PHP 7.0 and HHVM. (looks like the bug with 7.0 is fixed in the dev branch of superclosure, once they tag a release, we can make not allowed to fail)
    • Simplified PHPUnit config

    I do have some actual features coming, but my OCD was making me twitch so I'm sending this in first :)

    @hellogerard I see you don't have travis setup. Would you mind enabling it? All you have to do is create an account, and enable this repo. It will pick up the config file automatically. I did it earlier today for my fork and it only took a minute.

    opened by CarsonF 6
  • `haltDir' feature, some fixes, and a minor improvement

    `haltDir' feature, some fixes, and a minor improvement

    The main change here is to add the `haltDir' feature. It is useful for temporarily disabling a job.

    There are also some fixes, and a minor improvement.

    Of course, all changes in this pull request are cleanly separated out into distinct commits.

    opened by ruafozy 6
  • Failing to autoload

    Failing to autoload

    Using the same code as in the example for CommandExample Jobby is failing to autoload the vendor directory in BackgroundJob.php:

    PHP Warning:  require(/home/www/sites/vendor/hellogerard/jobby/vendor/autoload.php): failed to open stream: No such file or directory in /home/www/sites/vendor/hellogerard/jobby/src/Jobby/BackgroundJob.php $
    PHP Stack trace:
    PHP   1. {main}() /home/www/sites/vendor/hellogerard/jobby/src/Jobby/BackgroundJob.php:0
    PHP Fatal error:  require(): Failed opening required '/home/www/sites/vendor/hellogerard/jobby/vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/www/sites/vendor/hellogerard/jo$
    PHP Stack trace:
    PHP   1. {main}() /home/www/sites/vendor/hellogerard/jobby/src/Jobby/BackgroundJob.php:0
    

    Looks like Jobby is looking for the vendor autoload.php script inside it's own directory which doesn't exist as it should be in the root vendor directory (/home/www/sites/vendor/).

    opened by fire015 6
  • URL Command Support

    URL Command Support

    Is it possible to use wget or curl for url commands like below? If not currently supported, can this be added as a feature request or enhancement?

    require_once __DIR__ . '/vendor/autoload.php';
    
    $jobby = new Jobby\Jobby();
    
    // Every job has a name
    $jobby->add('CommandExample', [
        // Run a wget/cURL commands
        'command'  => 'wget http://localhost/cron/purgeErrorLog/',
    
        // Ordinary crontab schedule format is supported.
        // This schedule runs every hour.
        // You could also insert DateTime string in the format of Y-m-d H:i:s.
        'schedule' => '0 * * * *',
    
        // Stdout and stderr is sent to the specified file
        'output'   => 'logs/command.log',
    
        // You can turn off a job by setting 'enabled' to false
        'enabled'  => true,
    ]);
    
    $jobby->run();
    
    discussion 
    opened by parkerj 5
  • Check if job is due to run in main process

    Check if job is due to run in main process

    See #45

    [x] Adds ScheduleChecker class for determining if a job is due to run [x] Uses ScheduleChecker in BackgroundJob::shouldRun() [x] Moves use of ScheduleChecker to main process (Jobby::run())

    NB this pull request relies on changes made in #61

    opened by garethellis36 5
  • [Question] Why is shouldRun determined in background job?

    [Question] Why is shouldRun determined in background job?

    It seems like it would be way faster to determine which jobs should be started in main process (maybe aside from locking), then only run those background jobs. Thoughts?

    Also: This would also have a huge savings on not serializing closures that don't need to run.

    discussion 
    opened by CarsonF 5
  • Update dependencies

    Update dependencies

    I updated several dependencies to their latest versions. The reason behind, SuperClosure really needs to be updated. SuperClosure 1.* depends on nikic/php-parser v.0.9, which itself is outdated. I was not able to install jobby into my project, as other libraries, such as theseer/phpdox, require nikic/php-parser >= v.1.0. I thought this to be a code point to require php5.3.3, as depending libraries require this version (phpunit, symfony/filesystem).

    This change is dangerous, maybe jobby needs it's next minor-version. As SuperClosure changes the way, "scoped" closures are handled, jobby will not be BC-compatible. See changes in tests/Jobby/JobbyTest.php - as JobbyTest was not autoloadable from Jobby\BackgroundJob, I had to change the closures to be static-ones.

    opened by SchulteMarkus 5
  • Parameter to set location of debug.log

    Parameter to set location of debug.log

    debug | boolean | false | Send jobby internal messages to 'debug.log' -- | -- | -- | --

    Can you create a parameter to set the location / path of debug.log ? My scenario, the folder where jobby files are stored belong to ROOT, but the JOBBY files are running under APACHE (for security issues), so the debug.log cannot be write at the same folder of the .php file who was called. (ok, I put the output for each job called to correct folder, only debug.log cannot be defined in a different path)

    opened by mcunha98 0
  • putting the lck file outside the server ( redis or mysql / GCP, AWS)

    putting the lck file outside the server ( redis or mysql / GCP, AWS)

    Hi

    I want to work on a different way to put the lock file outside the server ( rewrite the functions ) so we can write the lock in REDIS / Mysql or simply AWS/GCP Storage for example using phpleague flysystem for files.

    this will help using jobby in a multi server environments for scalability :

    if Server 1 runs a job server 2 will not run the job until the job in server 1 is done

    what do you think ?

    opened by sidbenac 0
  • Does this library support system load average thresholds like fcron?

    Does this library support system load average thresholds like fcron?

    fcron has a feature to avoid starting jobs whilst system load is too high. It does this with configuration options such as lavg, or lavg1, lavg5 and lavg15 options which specify the threshold under which the system must be operating to begin the job. It may be combined with until to specify a timeout period after which the job would run regardless of load.

    Example

    # wait a maximum of 5 hours every day for a fall of the load average
    @lavgand,lavg(1,2.0,3.0),until(5h) 1d echo "Load average is going down" 
    

    For more, see fcrontab (5).

    opened by Bilge 0
  • Does this library support catch-up like anacron/fcron?

    Does this library support catch-up like anacron/fcron?

    If a system is restarted or otherwise down for some amount of time, jobs can be missed. Systems like anacron and fcron support "catching-up" for jobs that were missed. Does this library implement any kind of catch-up mechanism?

    opened by Bilge 0
  • Warning: exec() has been disabled for security reasons

    Warning: exec() has been disabled for security reasons

    Hi,

    When I try to execute a simple command, jobby return me this message:

    Warning: exec() has been disabled for security reasons in /home/userXXXX/domains/XXXXXXXXXX/public_html/vendor/hellogerard/jobby/src/Jobby.php on line 170

    I debug the exec command and try to execute it out of this file and work fine:

    <?php
    
    exec('/opt/alt/php73/usr/bin/php "/home/userXXXX/domains/XXXXXXX/public_html/vendor/hellogerard/jobby/bin/run-job" "Ejemplo" "jobClass=Jobby%5CBackgroundJob&mailer=sendmail&smtpPort=25&smtpSender=jobby%40nl-srv-web259.main-hosting.eu&smtpSenderName=jobby&runOnHost=nl-srv-web259.main-hosting.eu&output=%2Fhome%2Fu6userXXXX%2Fdomains%2FXXXXXXXX%2Fpublic_html%2Fcrons%2Flogs%2Funminut.log&dateFormat=Y-m-d+H%3Ai%3As&enabled=1&debug=0&command=ls&schedule=%2A%2F2+%2A+%2A+%2A+%2A" 1> /dev/null 2>&1 &')
    

    I put this file in the same folder than Jobby.php and it works.

    You know what is the problem?

    opened by phyron 0
Releases(v3.5.0)
Crunz is a framework-agnostic package to schedule periodic tasks (cron jobs) in PHP using a fluent API.

Crunz Install a cron job once and for all, manage the rest from the code. Crunz is a framework-agnostic package to schedule periodic tasks (cron jobs)

Reza Lavarian 1.4k Dec 26, 2022
Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch your crontab when deploying.

Dispatcher Dispatcher allows you to schedule your artisan commands within your Laravel project, eliminating the need to touch the crontab when deployi

Indatus 1.1k Jan 5, 2023
Easily implement optimistic Eloquent model locking feature to your Laravel app.

quarks/laravel-locking Easily implement optimistic Eloquent model locking feature to your Laravel app. Installation composer require quarks/laravel-lo

Quarks 2 Jun 21, 2022
xcron - the souped up, modernized cron/Task Scheduler for Windows, Mac OSX, Linux, and FreeBSD server and desktop operating systems.

xcron is the souped up, modernized cron/Task Scheduler for Windows, Mac OSX, Linux, and FreeBSD server and desktop operating systems. MIT or LGPL.

CubicleSoft 7 Nov 30, 2022
PHP cron job scheduler

PHP Cron Scheduler This is a framework agnostic cron jobs scheduler that can be easily integrated with your project or run as a standalone command sch

Giuseppe Occhipinti 698 Jan 1, 2023
Cron expression generator built on php8

The most powerful and extendable tool for Cron expression generation Cron expression generator is a beautiful tool for PHP applications. Of course, th

Pavel Buchnev 46 Nov 27, 2022
Task Scheduling with Cron Job in Laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Shariful Islam 1 Oct 16, 2021
Cron Job Manager for Magento 2

EthanYehuda_CronJobManager A Cron Job Management and Scheduling tool for Magento 2 Control Your Cron Installation In your Magento2 root directory, you

Ethan Yehuda 265 Nov 24, 2022
Laravel Cron Scheduling - The ability to run the Laravel task scheduler using different crons

Laravel Cron Scheduling Laravel Task Scheduling is a great way to manage the cron. But the documentation contains the following warning: By default, m

Sergey Zhidkov 4 Sep 9, 2022
Manage your Laravel Task Scheduling in a friendly interface and save schedules to the database.

Documentation This librarian creates a route(default: /schedule) in your application where it is possible to manage which schedules will be executed a

Roberson Faria 256 Dec 21, 2022
Manage Your Laravel Schedule From A Web Dashboard

Introduction Manage your Laravel Schedule from a pretty dashboard. Schedule your Laravel Console Commands to your liking. Enable/Disable scheduled tas

ⓒⓞⓓⓔ ⓢⓣⓤⓓⓘⓞ 1.6k Jan 5, 2023
Manage Your Laravel Schedule From A Web Dashboard

Introduction Manage your Laravel Schedule from a pretty dashboard. Schedule your Laravel Console Commands to your liking. Enable/Disable scheduled tas

ⓒⓞⓓⓔ ⓢⓣⓤⓓⓘⓞ 1.6k Jan 1, 2023
Modern and simple PHP task runner inspired by Gulp and Rake aimed to automate common tasks

RoboTask Modern and simple PHP task runner inspired by Gulp and Rake aimed to automate common tasks: writing cross-platform scripts processing assets

Consolidation 2.6k Jan 3, 2023
A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners.

PHP-Queue A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners. Why PHP-Queue? Implementing a

CoderKungfu 646 Dec 30, 2022
PHP port of resque (Workers and Queueing)

php-resque: PHP Resque Worker (and Enqueue) Resque is a Redis-backed library for creating background jobs, placing those jobs on one or more queues, a

Chris Boulton 3.5k Jan 5, 2023
A versatile and lightweight PHP task runner, designed with simplicity in mind.

Blend A versatile and lightweight PHP task runner, designed with simplicity in mind. Table of Contents About Blend Installation Config Examples API Ch

Marwan Al-Soltany 42 Sep 29, 2022
A course database lookup tool and schedule building web application for use at Rochester Institute of Technology.

CSH ScheduleMaker A course database lookup tool and schedule building web application for use at Rochester Institute of Technology. Built, maintained

Computer Science House 55 Nov 8, 2022
Schedule and unschedule eloquent models elegantly without cron jobs

Laravel Schedulable Schedule and Unschedule any eloquent model elegantly without cron job. Salient Features: Turn any Eloquent Model into a schedulabl

Neelkanth Kaushik 103 Dec 7, 2022
A horrendous PM plugin to manually load all the chunks in your world without logging on. Only for the sole purpose of aiding in PM4 -> DF world conversion.

ChunkLoader A horrendous PM plugin to manually load all the chunks in your world without logging on. Only for the sole purpose of aiding in PM4 -> DF

null 2 Aug 10, 2022
CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due

PHP Cron Expression Parser NOTE This fork has been deprecated and development moved to https://github.com/dragonmantank/cron-expression. More informat

Michael Dowling 4.9k Jan 5, 2023