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条)

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?