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

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

问题描述

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

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

类似于他们在 vBulletin 论坛中使用的内容.

Something similar to what they use in vBulletin Forum.

有人知道他们使用什么吗?他们是使用 cron 作业还是自定义完成了一些工作.

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

谁能指导我如何完成类似的事情,基本上我只是想让我的脚本添加或删除 cron 作业/计划任务.

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.

我不想使用,例如 cPanel Cron 界面,我想在我的脚本中完成这个.

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

非常感谢任何帮助.

推荐答案

如果你没有启用 exec() 功能,你必须依靠手动设置至少一个 cron 作业通过一些界面,然后在脚本中管理各个作业.

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.

我所做的就是这个

  1. 我有一个脚本 heartbeat.php 每分钟执行一次
  2. 此脚本检查 MySQL 表 crontab 并检查是否有任何带有 time_to_process time_to_process <= NOW()
  3. 的行(作业)
  4. 如果有,它从crontab表中加载为特定行定义的类
  5. 该类使用run() 方法实现了一个接口,我只调用$cronJob->run() 使其运行
  6. 该类然后在完成后通过 crontab 表处理它的重新调度
  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

一个很好的例子是重置某些项目的每日视图.作业安排在 2010 年 5 月 1 日 00:00.作业运行后,它会自动安排第二天的工作.
然后,您可以在 PHP 中实现失败作业的自动重置和许多其他功能.

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 管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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