I want to implement some kind of messaging queue system in our webproject. I'm just wondering what's the best way to do this. It's written in PHP (Yii Framework) with MySQL as the database system.
The idea:
I thought about 2 ways to do this:
Insert the message from User 1 in a 'message' table with a date and time the message should be delivered to User 2. User 2 can only read it when this date and time are smaller than the current date and time ( WHERE addTime <= NOW()
).
Insert the message from User 1 in a 'messageQueue' table. This is a table that contains all the messages that needs to be placed in the future. A cronjob (which will run every minute or so) will place all the messages with a date and time smaller than the current time into the 'message' table and deletes it from the 'messageQueue' table. An e-mail can be send directly to User 2.
Cons:
Does anyone have any idea to do this? I'm actually looking for some push function from the server/database, which tells my script that a new message is delivered to User 2 and that an e-mail needs to be send to User 2.
You can use CURL instead of CRON which will self request your "CRON JOB SCRIPT". It will be called after previous is finished. You might wanna delay CURL request if script will run under 1 minute or so.
Please consider using RabbitMQ implementing the AMQP model ( http://www.rabbitmq.com/ ). It might be a bit "overkill" given the context of the application, you've exposed.
However, if you already know for sure this messaging system would necessarily need to grow quickly, you might want to have a look at the documentation of php-amqplib
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.