One: The concept of the queue, data structure
Queues are a linear table in which operations are limited. Only allow inserts at one end of the table, and a linear table of deleted elements at the other end. A team tail (rear) is an end that allows insertion. The team head (front) is allowed to be deleted at one end. An empty queue is an empty table that contains no elements.
Suppose there is a queue q= (A1,a2,...,an), then A1 is the team head element, and an is the team tail element. The order of the elements is A1,a2,...,an, and the order of the team is A1,a2,...,an. The operations of the visible queues are based on the FIFO principle.
For more details, please search the Internet for a lot of information.
Two: the queue of PHP
Queues in PHP are expressed as arrays. The first element in the array acts as the team head and the last element as the tail, so that the queue can be manipulated.
The result is
There are many packaged classes on the web that can be used directly.
Array_push: Pushes one or more cells into the end of the array (into the stack)
Array_unshift: Inserts one or more cells at the beginning of the array
Array_pop: Eject the last cell of the array (out of stack)
Array_shift: Moves the cell at the beginning of the array to the group
Three: Ruby Starling
Starling is a lightweight, persistent server that supports the Memcache protocol. Starling is to make it easy to create a network access queue or multiple queues, i.e. asynchronous worker processes between multiple points and multiple machines. It is a well-known microblogging site Twitter developed to handle a large number of queue messages, as well as to maintain a service response. Starling has been used in production environments, not just by Twitter, but also by Fiveruns. Fiveruns even made improvements based on its own application.
Starling and Memcache are using a protocol that is just a different port. Starling is using port 22122 and Memcache is using 11211 ports.
Ruby tar xzvf ruby-1.9.1-p0.tar.gz cd ruby-1.9.1-p0./configure--prefix=/usr/local/huiyangruby make make install Gem tar -ZXVF rubygems-1.3.6.tgz cd rubygems-1.3.6 Ruby setup.rb Starling gem install memcache-client Starling Starling Starling & Amp Background execution Starling_top//view PS information |
Then you can use the queue to do your own thing. Starling and Memcache usage, the two work together better.
Use Memcache::addserver to establish a memcache connection pool. He is different from connect and pconnect he is in a request is only connected, no port connection.
Memcache::connect--Opens a connection to the Memcache.
Memcache::pconnect-Opens a long connection to the Memcache.
Memcache::close-Closes a Memcache connection.
Memcache::set-Saves the data to the Memcache server.
Memcache::get-Extracts a data saved on the Memcache server.
Memcache::replace-Replaces an item on a Memcache server that already exists (functions like memcache::set).
Memcache::delete-Deletes a saved item from the Memcache server.
Memcache::flush-Refreshes all items saved on the Memcache server (similar to deleting all saved items).
Memcache::getstats--Gets the status of the current Memcache server running.
Four: Zhang Yi works Httpsqs
HTTPSQS (http Simple Queue Service) is an HTTP Get/post protocol based lightweight open source Message Queuing services, using Tokyo Cabinet b+tree key/value database to do data persistence storage.
Interested can look at the URL: http://blog.s135.com/httpsqs_1_2/
V: Application of queues
Queues can handle data transfer and storage well asynchronously, and when you frequently insert data into a database and frequently submit data to a search engine, you can take a queue to insert it asynchronously. In addition, slower processing logic, concurrency-limiting processing logic, and background processing via Message Queuing, such as FLV video conversion, sending SMS, sending e-mail, and so on, can also be done. (Text/Hou Huiyang Phper.yang)