PHP 每小时更新一次
我正在开发一个基于另一个站点的数据生成动态图像的站点。问题是每次访问图像时从其他站点加载数据的速度都很慢。该图像在锦标赛网站上显示“团队”的当前统计数据。我想创建一个 cron 作业和数据库,它们协同工作,从团队上次更新时起每小时更新该特定“团队”的信息。例如,我可以有以下数据库字段:
ID, Name, Url, Wins, Losses, Xp, DateLastUpdated
因此,对于我的 cron 作业,我希望每次当前日期距上次更新日期一小时时更新条目。我该怎么做?我应该以特定的方式存储日期和时间吗?我是否应该使用日期以及应该多久运行一次 cron 作业?
I'm working on a site that generates a dynamic image based on data from another site. The problem is that loading the data from the other site ever time the image is accessed is slow. The Image displays the current stats of a "team" on a tournament website. I want to make a cron job and database that work together to update the info on a specific "team" every hour from when the team was last updated. For example, I could have the following db field:
ID, Name, Url, Wins, Losses, Xp, DateLastUpdated
So with my cron job, I want to update the entries every time the current date is an hour from the date last updated. How should I do this? Is there a specific way I should store the date and time? Should I even use a date and how often should I run the cron job?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有 unix 系统,请将文件放入
/etc/cron.hourly/myjob
中,其中包含以下内容:或通过
crontab -e
或任何接口都可以完成这项工作。它将每小时运行同步脚本:01
If you have a unix system, place a file in
/etc/cron.hourly/myjob
containing something like:or via
crontab -e
or any interfaceshould do the job. It will run sync-script every hour:01
您不需要存储上次更新图像的时间;您只需将 cron 作业设置为每小时运行一次即可。如果 cron 作业每小时运行一次,并且它是唯一创建映像的操作,那么您就知道在调用脚本时该映像正好是 1 小时前的版本。
You don't need to store the last time the image was updated; you can simply set your cron job to run hourly. If the cron job is running once per hour and it's the only thing creating the image, you know that the image is exactly 1 hour old at the time your script is invoked.