如何以自动方式定期执行PHP代码 [英] How to execute PHP code periodically in an automatic way

查看:46
本文介绍了如何以自动方式定期执行PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意定期截断MySQL数据库中的表,但是我不知道如何使代码自动在特定时间段(例如每周)运行.您知道这样做的任何方法或课程吗?

I am willing to truncate a table in a MySQL database periodically but I don't know how to make the code that does so run in a specific period of time automatically e.g every week. Do you know any approach or class to do so?

我在Windows服务器上

I am on windows sever

推荐答案

您有两种方法.

首先基于 cron作业-您的系统可能会每周自动调用一些PHP脚本.在 Wikipedia文章了解基于Cron的文章中了解更多(在GitHub的某处也看到了一些有趣的工具,但目前无法找到它).

First is based on cron jobs - your system may automatically call some PHP script every week. See more in Wikipedia article and learn Cron based on examples (I have seen also some interesting tool somewhere on GitHub, but I am unable to find it at the moment).

第二种方法是在执行不同脚本的过程中调用某些任务,例如当您无权访问crontab时.你可能会.在数据库中存储有关已执行脚本的信息-如果上次执行已过去7天,则执行一些功能/脚本并将新时间戳保存到数据库中.

The second is to call some task during execution of different script, eg. when you do not have access to crontab. You may eg. store information about executed scripts in the database - if 7 days have passed after last execution, then execute some function / script and save the new timestamp into the database.

您说过您在Windows上,但是也有类似cron的解决方案.

You said you are on Windows, but there are cron-like solutions also.

要添加计划任务,请遵循关于Drupal.org的文章中的指南.

To add scheduled tasks, follow the guidelines from article on Drupal.org.

您还可以运行类似Cron的软件,例如. CRONw-Windows版Cron .

You can also run Cron-like software, eg. CRONw - Cron for Windows.

这篇关于如何以自动方式定期执行PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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