0

We have decided to use redis as a message broker for our relatively small project and information out there on how to setup and use redis in production is very minimal. We use redis on aws. I have consulted this example: https://redis4you.com/code.php?id=012 and tested with a redis server locally and everything works fine.

However we are torn between using a crontab and daemon service and not exactly sure which is the best though implementing the cron is the easiest. I have researched on the generally acceptable way of doing but seen nothing.

Using a crontab means that I would have to exit the Slave.php file at some point with the snippet below which I am not totally comfortable with

public function processMessageInQueue(){
        while(!is_null($message_id = $this->predis->lpop("queue:message"))){

        $message = $this->predis->hgetall("message:$message_id");

        // Delete the key
        $this->predis->del("message:$message_id");

        // Process the message...
        $message = json_decode($message['message_data'], 1);
        $this->processMessage((array)$message);
    }

    exit(0);
}

Is there a better way of doing this or must it be done with either cron or a daemon service?

J.Ewa
  • 205
  • 3
  • 14
  • Based on this function alone, why would you need to exit? It seems as if once `while` is finished, that function will cease anyway. – spencdev Oct 11 '18 at 13:19
  • But we need the script to terminate because it will be invoked again in 'x' minutes with another crontab. – J.Ewa Oct 11 '18 at 13:36
  • What is keeping it alive? The redis connection? In my opinion, I believe the daemon service would be a better option, although not the fastest route to live. – spencdev Oct 11 '18 at 13:42
  • I believe it is the connection that keeps it alive. The daemon service would be better and involves a lot of hassle but we also were curious if there are other options out there. The cron seems to be the easiest to implement with the resources we have atm. – J.Ewa Oct 11 '18 at 13:58

0 Answers0