2

Context
I need to warn my website's users of events by sending them an email when they're offline or display them a javascript notification if they're online (using websockets/push events).
Some of these events should be triggered after a certain amount of time (for specific app/business logic).

I won't use sleep() since it may causes performances issues.

How would you manage to do that using Crontab and/or CLI ?

younes0
  • 2,288
  • 1
  • 25
  • 34
  • They are on the same machine and also they will share the same database, there are still performance issues. It's just a matter of what you want to look and overlook – Alexander Oct 20 '12 at 10:01
  • By talking of performance issues, I mean not having the inconvenients of sleep() method. – younes0 Oct 20 '12 at 10:06

1 Answers1

0

If you have a socket and you can send and it gets delivered then it's ok. You can check it off. Otherwise it has to be mailed. That's the whole logic. So just try to see if you can send over socket otherwise send mail. Don't wait for it:

Use some queue software for this, this is really a clean messages queue which can be implemented by quite standard solutions. So just send it to the queue and do the logic in your queue scripts.

You can never implement waiting much better than queues which are good at that unless you have very specific needs.

Some options to answer more specific: http://www.javacodegeeks.com/2012/04/rabbitmq-scheduled-message-delivery.html

Simple scalable work/message queue with delay

Community
  • 1
  • 1
Luc Franken
  • 2,994
  • 1
  • 17
  • 14
  • This doesn't answer to my question sorry. Delivering issues are not, I'd like to delay that delivering. – younes0 Oct 20 '12 at 10:27
  • Most queue software does that for free. That's why I think this is a complete solution for your question, it allows you to do all requested without having to develop all by yourself on a proven scalable way. – Luc Franken Oct 20 '12 at 10:30
  • 1
    Thanks, I get it now. So PHP is not suitable at all for this, and the solution as you mentionned is to use a Jobs Queue Server like Beanstalkd or Redis... Here's a example to illustrate this : http://www.justincarmony.com/blog/2012/01/10/php-workers-with-redis-solo/ – younes0 Oct 24 '12 at 16:41
  • One great answer on how to use PHP Resque library : http://stackoverflow.com/questions/11814445/what-is-the-proper-way-to-setup-and-use-php-resque# – younes0 Oct 24 '12 at 16:53