在PHP中使用cron manager [英] Using cron manager from within PHP

查看:318
本文介绍了在PHP中使用cron manager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的php应用程序中添加一个部分以添加/删除计划的任务。



类似于 vBulletin论坛



有没有人有什么想法他们使用什么?是他们使用cron工作还是有自定义的工作。



任何人都可以指导我如何完成类似的东西,基本上我只是想让我的脚本添加或删除cron作业/计划任务。



我不想使用,例如cPanel Cron接口,我想在我的脚本中完成。 / p>

任何帮助都非常感谢。

解决方案

已启用 exec()函数,您必须依靠通过某个界面手动设置至少一个cron作业,然后在脚本中管理单个作业。



我做的例子是


  1. 我有一个脚本 heartbeat crontab ,并检查是否存在这个脚本 任何具有 time_to_process <= NOW()

  2. 的行(作业)如果存在,则加载为特定行定义的类 crontab

  3. 该类实现了一个具有 run()我只需调用 $ cronJob-> run()即可运行

  4. 然后该类通过 crontab 表完成后

一个很好的例子是重置某些项目的每日视图。
该工作安排在2010年5月1日00:00。一旦作业运行,它会自动调度自己。

然后,您可以在PHP中自动重置失败的作业和许多其他功能。


I am wanting to add a section in my php application to add / remove scheduled tasks.

Something similar to what they use in vBulletin Forum.

Does anyone have any ideas what they use? Are they using cron jobs or do they have something custom done.

Can anyone guide me on how I can accomplish something similar to that, basically I just want my script to add or remove cron jobs / scheduled task.

I don't want to use, for example the cPanel Cron interface, I would like to accomplish this from within my script.

Any help is greatly appreciated.

解决方案

If you don't have the exec() function enabled, you have to rely on manually setting at least one cron job via some interface and then managing individual jobs in your script.

What I do for example is this

  1. I have a script heartbeat.php which is executed every minute
  2. This script checks a MySQL table crontab and checks if there is any row (job) with time_to_process <= NOW()
  3. If there is, it loads the class defined for the specific row from crontab table
  4. The class implements an interface with run() method and I only call $cronJob->run() to make it run
  5. The class then handles it's rescheduling via crontab table once it finishes

A good example is to reset daily views on some items. The job is scheduled at May 1, 2010 00:00. Once the job ran, it schedules itself for the next day automatically.
You can then implement automatic reset of failed jobs and many other features from within PHP.

这篇关于在PHP中使用cron manager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆