在 PHP 中使用 cron 管理器

2023-08-17php开发问题
4

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

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17