doubingjiu3199 2011-07-01 16:16
浏览 25
已采纳

在基于云的环境中运行PHP cronjobs

I'm looking for PHP solutions for running cronjobs over multiple servers and guaranteeing that only a single server runs these cronjobs automatically. We have cronjobs that we need to run only once, like daily digest emails or weekly reports.

Right now, we have a "master" server which has the crontab installed, and multiple "normal" servers which only have apache installed on them. The issue is that if the "master" server fails, nobody will run the cronjob anymore. It also means we need to keep track on which server is the master and it's creating some scaling issues for us.

Are there any ready-made php solutions for running unique tasks by multiple servers?

I have looked at gearman (http://www.slideshare.net/felixdv/high-gear-php-with-gearman), but it's a little too complex . I just need to guarantee that only one server out of the farm runs the cronjobs.

  • 写回答

2条回答 默认 最新

  • douchun1900 2011-07-01 16:54
    关注

    I build my concurrency and 'running' checks in the scripts themselves.

    Update a 'lock' in the database or in memcached that states the last execution time.

    If that lock is present, bail in the other copies of the script... unless the lock is too old.
    If the lock has been sitting around > max_execution, the script failed or ran too long and never unlocked. Email yourself on that condition.

    Remember to unset the lock at script close.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?