doujing2017 2012-07-06 20:03
浏览 61
已采纳

使用cron系统地更新数据库

I am developing software that is similar to fantasy football applications.

I have user accounts with information pertaining to each of them stored in a relational database in mysql. I have a php script that I want to run after all of the games are finished to update every member's stats at once (there could be thousands of users).

After researching it seems like the best solution would be to set up a cron tab using Unix.
I am wondering if this would be the correct solution?

If I set up this crontab to run every Tuesday would it run the PHP script which would update the user information?

Is a cron tab easy to set up with Unix for a simple website?

  • 写回答

1条回答 默认 最新

  • doukuilian8365 2012-07-06 20:17
    关注

    Setting up crons is really simple. If you have shell access, simply type #crontab -e and it will bring you to the cron settings. Check out this link: Crontab - Quick Reference.
    What you simply do is create a PHP script and link it through the cron tab. If you are running a server with cPanel, there is a built-in cron manager too, if you prefer to do it in a GUI.

    You did not give enough information for me to say anything conclusive about this, but you want to balance the script out so that it either 1) runs frequently enough so that it has to update small enough changes--for example, if 100 records are changed every hour, running the script every day will mean it has to update 2400 records, whereas if you run it once a week, it has to update 16800 recods, which probably is so severe that it will raise your server load. And/ or 2) break up your updates in chunks. For example if records only change once a week, but at that time 16800 records change, then you might want to either have your scripts run for 1000 updates and put it to sleep for a while, run some more, sleep, etc (this is a bad habit, but it is the simplest I suppose), or you run your cron script frequently, every time it does 1000 updates, and at the end of it, it will leave a trace (for example, the last ID number) of the last change it has updated into the database so that the script can pick up on that the next time it runs.

    If you want me to draft up some more elaborate examples the illustrate the two different approaches, please let me know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里