如何在 PHP 中实现 cron?

2022-01-03 00:00:00 cron php

我使用网络托管 startlogic.com.我向一名员工询问了有关 cron 的问题.他们告诉我,他们的控制面板中只有一个名为计划作业"的功能.我可以在哪里手动放置作业.但我需要从我的 Web 应用程序中执行此操作.例如,当我按下按钮时,我会在 1 个月后收到电子邮件通知.如何使用 PHP 实现这一点?

I use a web-hosting startlogic.com. I asked an employee about cron. They told me that they only have a feature in the control panel called "Schedule jobs" where I can manually put the job. But I need to do this from my web application. For example, when I push a button, I will receive an email notification after 1 month. How to implement this using PHP?

推荐答案

  1. 制作一个名为 cron.php 的 PHP 脚本(如果可能,请在您的 Web 根目录之外).

  1. Make a PHP script called cron.php (outside of your web root if possible).

将此设置为在计划作业"下定期运行

Set this to run regularly under "Schedule Jobs"

每次运行 cron.php 时,它都会检查作业数据库以查看是否有任何到期.

Every time cron.php runs, it checks a database of jobs to see if any are due yet.

如果有任何到期,它们就会运行.

If any are due, they are run.

一旦运行,它们就会被标记为这样.

Once run, they are marked as such.

要将新工作添加到列表中,只需在数据库中添加一个包含工作详细信息和截止日期的新行.

To add new jobs to the list, just add a new row to the database with the details of the job and the due date.

相关文章