如何在PHP中的函数上设置24小时的时间延迟?

发布于 2025-01-05 21:42:12 字数 125 浏览 4 评论 0原文

我有一个用 php5 编写的网络应用程序。

该应用程序允许用户注册,我想延迟发送密码和链接等各种详细信息。我希望包含此信息的电子邮件在用户拒绝后 24 小时内发送。

如何执行24小时后发送电子邮件的功能?

I have a web application written in php5.

The application allows users to register and I would like to delay when the various details such as password and links will be sent out. I would like the email containing this information to go 24h after a user has resisted.

How can I to execute the function that will send the email after 24 hours has passed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昨迟人 2025-01-12 21:42:12

这取决于“24”小时的准确程度,但类似以下方法应该可行。

创建一个表来保存用户注册,或调整现有表来保存 registrationTime 列。使此列可空 DATETIME 您将用它来保存 HH:MM
用户注册。新的(或修改的)表还应该具有与电子邮件相关的数据,或者用户的通用标识符,从而允许选择正确的数据。

最后,您将设置一个 cron 作业,每 x 分钟 查询一次数据库,并选择在 24 小时的 y 分钟 内注册的用户。其中,x 是您希望作业运行的频率,y 是对接近 24:00 小时的时间的某种程度的容忍度。

对于任何结果,您都可以构建并发送电子邮件。最后,您可以设置一些标志来显示用户已被处理 - 一个好方法是将所有已发送电子邮件的用户的 registrationTime 设置为 null。

以下是一些可以帮助您解决问题的链接:

Compare time in SQL Server
如何比较 SQL Server 中的时间?

介绍 Cron
http://www.sitepoint.com/introducing-cron/

It would depend on how accurate '24' hours needs to be, but something like the following approach should work.

Create a table to hold user registrations, or adapt an existing table to hold a registrationTime column. Make this column nullable DATETIME you will use it to hold the HH:MM
of the users registration. The new (or modified) table should also have the data relevant for the emails, or a common identifier for users, allowing the correct data to be selected.

Finally, you would set up a cron job to query the data base every x mins and select the users who registered within y mins of 24hours. Where x is how often you want the job to run and y would be some degree of tolerance for how close to 24:00 hours had elapsed.

For any results you would construct and send the emails. Finally you would set some a flag to show that user had been dealt with - a good way would be setting the registrationTime to null for all users who have had the email sent.

Here are a few links to help you out:

Compare time in SQL Server
How can I compare time in SQL Server?

Introducing Cron
http://www.sitepoint.com/introducing-cron/

把昨日还给我 2025-01-12 21:42:12

我将设置处理您的电子邮件队列的数据库表。该表可以有一列指定对应于一封电子邮件的每一行的排队时间。您可以运行一个 cron 作业,假设每小时左右运行一次,检查 24 小时是否已过。

email_type   | to             | data
--------------------------------------------------------------------------
registration | [email protected] | {first_name: "Fred", last_name: "Stuff" }

此解决方案非常灵活,因为您可能希望将其他类型的电子邮件延迟不同的时间。您可以添加一列来指示电子邮件的类型以及您的代码以不同方式处理每种类型。

此 cronjob 将每小时运行一次:

0 * * * * php check_mail_queue.php

您可以添加一列来指示电子邮件是否已发送,也可以直接删除该行。另外,如果您要在每封电子邮件中包含自定义数据,请序列化数组、哈希、字典等,并将其也存储到表中的列中。

I would setup database table that handles your email queue. This table can have a column that specifies when each row, corresponding to one email, was queued up. You can have a cron job running, let's say every hour or so, that checks if the 24 hours has elapsed.

email_type   | to             | data
--------------------------------------------------------------------------
registration | [email protected] | {first_name: "Fred", last_name: "Stuff" }

This solution is flexible because you might have other types of emails that you want delayed by different amounts of time. You can add a column that indicates what type of email and your code handles each type differently.

This cronjob will run every hour:

0 * * * * php check_mail_queue.php

You can either add a column that indicates whether an email's been sent or simply delete the row. Also, if you're going to have custom data in each email, serialize the array, hash, dictionary, whatever, and store that into a column in the table too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文