PHPackages                             jenner/crontab - 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. jenner/crontab

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

jenner/crontab
==============

php crontab base on pcntl and libev

v1.5.1(10y ago)30791994[3 issues](https://github.com/huyanping/php_crontab/issues)MITPHPPHP &gt;=5.3.0CI failing

Since Nov 10Pushed 6y ago32 watchersCompare

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

READMEChangelog (7)Dependencies (5)Versions (6)Used By (0)

php\_crontab
============

[](#php_crontab)

[![Latest Stable Version](https://camo.githubusercontent.com/964d592e0d5b8b778e4a41a315d70eb1c250fee7fbaf75850300ea5930bb45b1/68747470733a2f2f706f7365722e707567782e6f72672f6a656e6e65722f63726f6e7461622f762f737461626c65)](https://packagist.org/packages/jenner/crontab)[![Total Downloads](https://camo.githubusercontent.com/9fe93e58422ce86b1f86a15ab7e2f4188699da5ffb4f63afeca53ec126d3bbd0/68747470733a2f2f706f7365722e707567782e6f72672f6a656e6e65722f63726f6e7461622f646f776e6c6f616473)](https://packagist.org/packages/jenner/crontab)[![Latest Unstable Version](https://camo.githubusercontent.com/78d2138c9f867d10cc150629303e67d77293f6e15f18f7f6f414fc0e38c9d50f/68747470733a2f2f706f7365722e707567782e6f72672f6a656e6e65722f63726f6e7461622f762f756e737461626c65)](https://packagist.org/packages/jenner/crontab)[![License](https://camo.githubusercontent.com/74fd7fa8975b1f04a538a29ccc5de0d958697c98f17a0ba01a79c0a439b65405/68747470733a2f2f706f7365722e707567782e6f72672f6a656e6e65722f63726f6e7461622f6c6963656e7365)](https://packagist.org/packages/jenner/crontab)[![License](https://camo.githubusercontent.com/26298bdb57f540eb38c674c23eb477ea6cf62c4ab2e07d0a13d26193f0f174eb/68747470733a2f2f7472617669732d63692e6f72672f687579616e70696e672f7068705f63726f6e7461622e737667)](https://travis-ci.org/huyanping/php_crontab.svgb)

php crontab base on pcntl and react/event-loop

[中文说明](https://github.com/huyanping/php_crontab/blob/master/README.zh.md "中文说明")

Why use php\_crontab?
---------------------

[](#why-use-php_crontab)

When we have a handful of crontab tasks, crontab service is enough for us to manage them. If we have many crontab tasks, there will be some problems like:

- The crontab tasks are managed in a text file. If there are no comment, it will be hard for fresh man to understand what they are.
- If the crontab tasks are distributed in different servers, it will be hard to manage them.
- If you want to collect the crontab tasks' logs, it will be not easy.
- Tasks of different users must written in different files. Based on the above reasons, we need a crontab manager which can manage crontab tasks together and configure the tasks.

How to use php\_crontab?
------------------------

[](#how-to-use-php_crontab)

First `composer require jenner/crontab`.
There are two ways to use php\_crontab to manage your crontab tasks. You can just write a php script and add it to the crontab config file with the command `crontab -e`. The php script should run every minute. For example `tests/simple.php`
Or you can write a php daemon script which will run as a service and will not exit until someone kill it. It will check the tasks every minute. For example `tests/daemon.php`

Import
------

[](#import)

```
composer require jenner/crontab
```

Properties
----------

[](#properties)

- The crontab tasks can be stored in any way you what. For example, mysql, reids. What's more? You can develop a web application to manage them.
- The tasks of different users can be managed together.
- Multi-Process, every task is a process.
- You can set the user and group of a crontab task
- STDOUT can be redirected
- Based on react/event-loop, it can run as a daemon.
- A HTTP server which you can manage the crontab tasks through it.
- Dynamic task loader, you can register a task loader by Daemon::registerTaskLoader, which will execute every 60 seconds and update the crontab tasks.

HTTP interfaces
---------------

[](#http-interfaces)

HTTP METHOD: `GET`

- `add` add new task to crontab server
- `get_by_name` get task by name
- `remove_by_name` remove task by name
- `clear` clear all task
- `get` get all tasks
- `start` start crontab loop
- `stop` stop crontab loop

Examples:

```
http://host:port/add?name=name&cmd=cmd&time=time&out=out&user=user&group=group&comment=comment
http://host:port/get_by_name?name=name
http://host:port/remove_by_name?name=name
http://host:port/clear
http://host:port/get
http://host:port/start
http://host:port/stop
```

TODO
----

[](#todo)

- add log handler interface.
- add http log handler, socket log handler, file handler and so on.
- separate stdout and stderr. use different handlers

**run based on crontab service**

```
* * * * * php demo.php
```

```
