PHPackages                             mattmezza/scheduled-job - 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. [CLI &amp; Console](/categories/cli)
4. /
5. mattmezza/scheduled-job

ActiveLibrary[CLI &amp; Console](/categories/cli)

mattmezza/scheduled-job
=======================

A package to run scheduled job with cron.

1.0.0(7y ago)121MITPHPPHP ^7.1

Since Feb 11Pushed 7y ago2 watchersCompare

[ Source](https://github.com/mattmezza/php-scheduled-job)[ Packagist](https://packagist.org/packages/mattmezza/scheduled-job)[ RSS](/packages/mattmezza-scheduled-job/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (2)Used By (0)

scheduled job
=============

[](#scheduled-job)

[![Travis (.org)](https://camo.githubusercontent.com/e35a668c28f3f689b44f88ecac099b8d4b52992e926e14816c3095d83a5dd7da/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6174746d657a7a612f7068702d7363686564756c65642d6a6f622e737667)](https://github.com/mattmezza/php-scheduled-job)

Installation
------------

[](#installation)

`composer require mattmezza/scheduled-job`

Usage
-----

[](#usage)

##### 1. Create a task

[](#1-create-a-task)

```
class MyTask extends TaskStandard {

    public function getDescriptionString(): string
    {
        return 'Task description';
    }

    public function run(array $allParam)
    {
        // do something
    }
}
```

##### 2. Create a job

[](#2-create-a-job)

```
class MyJob extends JobStandard {

    public function getDescriptionString(): string
    {
        return 'Job description';
    }

    public function getAllTask(): array
    {
        return [
            new MyTask(),
        ];
    }
}
```

##### 3. Run the job

[](#3-run-the-job)

```
(new JobExecutorStandard())->execute($job, $argv]);
```

##### 4. Observe jobs and tasks

[](#4-observe-jobs-and-tasks)

You can attach observers to both jobs and tasks.

```
$job->addObserver(new JobLogger());
$task->addObserver(new TaskLogger());
```

You can define custom observers by implementing `JobObserver` and `TaskObserver`.

##### 5. Automate with cron

[](#5-automate-with-cron)

Create a PHP script file that you can run via cron `~/your-project/your-job.php`:

```
#!/usr/bin/env php
