博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php crontab扩展,croon
阅读量:4363 次
发布时间:2019-06-07

本文共 2611 字,大约阅读时间需要 8 分钟。

Croon fd4a65b6ca044937bb7097c33d5705c3.png

Croon是一个PHP版本的CronTab实现

之前也做过一个类似的实现php-crontab,Croon与之不同的是:使用进程管理方式Fork工作进程;有友好的日志模块;加入事件驱动;更佳规范和稳定

功能:

兼容CronTab语法

精确到秒级控制

支持事件绑定

支持日志

依赖

PHP 5.3.9+

ext-pcntl

ext-posix

库依赖(使用composer install自动安装)

安装

下载使用:

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数据库为计划任务源

修改数据库连接信息 bin/croon_with_mysql

表结构为

+---------------------+--------------------------------------------------------+

| time | command |

+---------------------+--------------------------------------------------------+

| [秒] 分 时 日 月 周 | command |

+---------------------+--------------------------------------------------------+

执行

./bin/croon_with_mysql -l croon.log

高级用法

bootstrap.php

// 绑定启动事件

$croon->on('run', function() use($croon) {

// 注入db

$croon->db = new \PDO('mysql://localhost:3306;dbname=reports');

});

// 绑定执行事件

$croon->on('executed', function ($command, $output) use ($croon) {

// 记录执行结果

$croon->db->exec(sprintf(

'INSERT INTO cron(command, status, stdout, stderr, create_time) VALUES ("%s", "%s", "%s", "%s", "%s")',

$command, $output[0], $output[1], $output[2], date('Y-m-d H:i:s'))

);

});

执行

./bin/croon croon.list -l croon.log -b bootstrap.php

License

(The MIT License)

Copyright (c) 2012 hfcorriez

Permission is hereby granted, free of charge, to any person obtaining

a copy of this software and associated documentation files (the

'Software'), to deal in the Software without restriction, including

without limitation the rights to use, copy, modify, merge, publish,

distribute, sublicense, and/or sell copies of the Software, and to

permit persons to whom the Software is furnished to do so, subject to

the following conditions:

The above copyright notice and this permission notice shall be

included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,

EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY

CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,

TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE

SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

转载地址:http://tqkfs.baihongyu.com/

你可能感兴趣的文章
物联网架构成长之路(8)-EMQ-Hook了解、连接Kafka发送消息
查看>>
2018-2019-1 20165234 20165236 实验二 固件程序设计
查看>>
IDEA的GUI连接数据库写入SQL语句的问题总结
查看>>
Xpath在选择器中正确,在代码中返回的是空列表问题
查看>>
leecode第一百九十八题(打家劫舍)
查看>>
【BZOJ 1233】 [Usaco2009Open]干草堆tower (单调队列优化DP)
查看>>
07-3. 数素数 (20)
查看>>
写一个欢迎页node统计接口Py脚本(邮件,附件)-py
查看>>
计算两个日期之间的天数
查看>>
Android关于buildToolVersion与CompileSdkVersion的区别
查看>>
袋鼠云日志,日志分析没那么容易
查看>>
缓存穿透 缓存雪崩 缓存并发
查看>>
了解你的Linux系统:必须掌握的20个命令
查看>>
js setInterval 启用&停止
查看>>
knockoutJS学习笔记04:监控属性
查看>>
Linux下启动/关闭Oracle
查看>>
session和cookie的区别
查看>>
alert弹出窗口,点击确认后关闭页面
查看>>
oracle问题之数据库恢复(三)
查看>>
单点登陆(SSO)
查看>>