Implementing Message Queuing in PHP Memcache
Memcache is typically used for caching services. But a lot of times, like a message broadcast system, need a message queue. Fetching messages directly from a database is often not a load. If the entire message queue is cached with a key into memcache.
For a large message queue, it is too expensive to serialize and deserialize large databases frequently. Here is a message queue I implemented in PHP, only need to insert a data at the end of the operation of the tail, do not operate the entire message queue to read, and operation. However, this message queue is not thread-safe, I just try to avoid the possibility of conflict. If the message is not very dense, such as a few seconds to one, you can still consider this use.
If you want to implement thread-safe, one suggestion is to lock through the file and then do the operation. Here's the code:
Copy the code code as follows:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.