walkor / crontab Goto Github PK
View Code? Open in Web Editor NEWA crontab written in PHP based on workerman
A crontab written in PHP based on workerman
$crontab_worker->onWorkerStart = function ($crontab_worker) use ($app) {
new Crontab('0 0 * * *', $app->boot('/article/sitemap/main'),'sitemap');
new Crontab('*/15 * * * *', $app->boot('/multimedia/migration'),'migration_image');
new Crontab('*/19 * * * *', $app->boot('/article/migration'),'migration_article');
};
as you can see, if we execute multiple crontabs there, the memory usage keeps increasing. I am not sure if it's the right way to execute multiple crontab all at once.
1.0.4 版本开始,下一秒就开始执行定时任务。
但是发现有问题,到下一分钟执行频率乱套了,场景复现如下:
代码:
https://foruda.gitee.com/images/1673683751262076072/c5e83612_5507348.jpeg
执行记录:
https://foruda.gitee.com/images/1673683815022015587/9ae2e73b_5507348.jpeg
new两个Crontab() ,第一个每分钟第一秒执行,第二个每分钟第二秒执行,如果第一个执行sleep70秒,那么在第五秒的时候好像触发不到第二个任务,或者说,触发了,但是没能执行到,要等70秒后才会执行。这是Windows下php的问题吗?
$worker->onWorkerStart = function () {
// Execute the function in the first second of every minute.
new Crontab('1 * * * * *', function(){
echo "[1]start:".date('Y-m-d H:i:s')."\n";
sleep(70);
echo "[1]end:".date('Y-m-d H:i:s')."\n";
});
new Crontab('2 * * * * *', function(){
echo "[2]start:".date('Y-m-d H:i:s')."\n";
sleep(70);
echo "[2]end:".date('Y-m-d H:i:s')."\n";
});
};
运行:
[1]start:2022-07-02 17:15:01
[1]end:2022-07-02 17:16:11
[2]start:2022-07-02 17:16:11
[2]end:2022-07-02 17:17:21
请问这个定时任务是单进程,会造成阻塞的吗?
如果有多个crontab想要从数据库取出配置,并且可以独立不造成阻塞 怎么做必要好。
new Crontab()
那么从执行的测试结果上来看,好像是堵塞的,并不会按执行频率定时执行。
https://foruda.gitee.com/images/1673853265699053939/f1da68b8_5507348.jpeg
现在大部分新的workerman项目都上4.0了,这个lib最好也跟进
1.composer.json中标记为"php": ">=5.4"即可,导致php版本5.6 5.4 5.5可以直接安装,而您写的start.php会报错,因为crontab的解析类语法是>=7.0 例如 string xxx int xxx function():bool
2.如果要是只支持7.0,那么需要修改composer.json ,如果需要支持>=5.4,还需要修改,我看到这个问题,不知道应该如何修复并提交上来
eg: * * 7-10/1 * * *
当尝试设置指定时间段内执行的定时任务,比如7-10点之间,该语法解析结果为[0,1,2,3,4,5,6,7,8,9,10]。
正常解析结果:[7,8,9,10]
看了下hyperf的源码,应该是最新的代码未同步
执行 php crontab.php reload 或者 php crontab.php stop 命令时 是否会立刻停止当前的定时任务(假设此时定时任务还未执行完成)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.