PHPackages                             croon/croon - 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. croon/croon

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

croon/croon
===========

Crontab for PHP

0.2.1(11y ago)14410236[2 issues](https://github.com/hfcorriez/croon/issues)[1 PRs](https://github.com/hfcorriez/croon/pulls)MITPHPPHP &gt;=5.3.9

Since May 2Pushed 5y ago13 watchersCompare

[ Source](https://github.com/hfcorriez/croon)[ Packagist](https://packagist.org/packages/croon/croon)[ RSS](/packages/croon-croon/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Croon [![Build Status](https://camo.githubusercontent.com/10179f3fc7bd6f956b0ab2c3ee985411bd05e25f96ae7cdf781f4e315586bd91/68747470733a2f2f7472617669732d63692e6f72672f6866636f727269657a2f63726f6f6e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/hfcorriez/croon)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#croon-)

Croon是一个PHP版本的CronTab实现

之前也做过一个类似的实现[php-crontab](https://github.com/hfcorriez/php-crontab)，Croon与之不同的是：使用进程管理方式Fork工作进程；有友好的日志模块；加入事件驱动；更佳规范和稳定

功能：
---

[](#功能)

- 兼容CronTab语法
- 精确到秒级控制
- [PSR标准](https://github.com/hfcorriez/fig-standards)
- 支持事件绑定
- 支持日志

依赖
--

[](#依赖)

- PHP 5.3.9+
- ext-pcntl
- ext-posix
- [Composer](http://getcomposer.org)

库依赖（使用`composer install`自动安装）

- [pagon/childprocess](https://github.com/hfcorriez/php-childprocess)
- [pagon/eventemitter](https://github.com/hfcorriez/php-eventemitter)
- [pagon/logger](https://github.com/pagon/logger)
- [pagon/argparser](https://github.com/hfcorriez/php-argparser)

安装
--

[](#安装)

下载使用：

[Latest Release](https://github.com/hfcorriez/croon/releases/)

Git:

```
git clone git://github.com/hfcorriez/croon.git
cd croon
composer install

```

Composer

```
composer require croon/croon

```

使用
--

[](#使用)

### 基本用法

[](#基本用法)

`croon.list`

```
* * * * * * ls -l >> /tmp/ls.log

# 兼容系统crontab
* * * * * pwd >> /tmp/pwd.log

```

执行

```
./bin/croon croon.list -l croon.log

```

`croon.log`

```
[2013-04-20 14:07:01] 27a6c9 -  debug   - Croon...!!!
[2013-04-20 14:07:01] 27a6c9 -   info   - Execute (ls >> /tmp/ls.log)
[2013-04-20 14:07:01] 27a6c9 -   info   - Finish (ls >> /tmp/ls.log)[0]

```

### 以mysql数据库为计划任务源

[](#以mysql数据库为计划任务源)

- 修改数据库连接信息 bin/croon\_with\_mysql
- 表结构为

```

+---------------------+--------------------------------------------------------+
| time                | command                                                |
+---------------------+--------------------------------------------------------+
| [秒] 分 时 日 月 周   | command                                                |
+---------------------+--------------------------------------------------------+

```

执行

```
./bin/croon_with_mysql -l croon.log

```

### 高级用法

[](#高级用法)

`bootstrap.php`

```
