如果一周过去了,则运行 MySQL 查询
首先,我是一个初学者,我不想让任何人为我编写代码。我只是想从更有经验的开发人员那里得到一点提示。
我有一个视频网站,它使用 XML 从另一个网站加载视频,并将有关视频的信息保存在数据库中。我想做的是,如果一周过去了,自动运行插入查询。
我以前从未这样做过,也从未使用过这样的时间函数。那么请问有人可以展示他的计划他将如何做到吗?所以没有代码,只是解释一下过程。
First of all I am a beginner, and I don't want anybody to write code for me. I would just like a bit of a hint from a more experienced developer.
I have a video site, what loads videos from another website with XML and saves info about the videos in the database. What I would like to do is that if a week is passed, automatically run the insert query.
I never did this before and never worked with time functions like this. So please could someone show his plan how he would do it? So no code, just explain the process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我建议设置一个 cron: http://en.wikipedia.org/wiki/Cron
I'd recommend setting up a cron: http://en.wikipedia.org/wiki/Cron
我不认为这是一个与编码相关的问题。可以通过使用 cron 来实现任务分配。
Cron 是一个任务调度程序,当它可用于您的主机时,可以通过主机控制面板进行访问。你的主人是什么?
I dont think this is a coding-related problem. Tasking can be achieved by using cron.
Cron is a task scheduler, which when its available for your hosting, can be accessed at the hosting control panel. What is your host ?
您可以使用Cronjobs。
You could use Cronjobs.
您想如何处理中间一周的数据?我希望您不希望让进程运行一周然后执行插入。
您可以执行一些操作,例如加载 XML 并将其保存在数据库中,将
active
列设置为 0。您可以在执行插入时保存时间戳。同时,使用 cron,您可以让脚本每 X 分钟或每小时运行一次,检查数据库中一周不活动的项目,然后将它们更新为活动状态。
What do you want to do with the data in the week in between? I hope you're not hoping to keep a process running for a week and then execute the insert.
You could do something like load the XML and save it in the database, setting an
active
column to 0. You save the timestamp at the moment the insert is executed.Meanwhile, using cron, you let a script run every X minutes or hours, checking the database for items that have been inactive for a week, and then updating them to become active.
您可以使用 time() 函数。它返回自 1970 年 1 月 1 日以来的秒数。
然后,例如,您取 t = 0 时的时间。
当时间()-t>时一周(= 3600 * 24 * 7 秒),你知道一周过去了。
You can use the time() function. It returns the number of seconds since January, 1st, 1970.
Then, for example, you take the time at t = 0.
When time() - t > a week (= 3600 * 24 * 7 seconds), you know a week has passed by.