A: The concept of the queue, data structure
A queue is a linear table in which operations are constrained. Only one end of the table is allowed to be inserted, while the other end is a linear table that deletes elements. The end of the queue (rear) is one end of the allowable insertion. The team header (front) is the one end that is allowed to delete. An empty queue is an empty table with no elements.
Assuming there is a queue q= (A1,a2,...,an), the A1 is the team head element, an is the tail element of the team. Elements are queued in the order of A1,a2,...,an, and the order of the team is A1,a2,...,an. The operation of the visible queue is based on the FIFO principle.
For more details, please search the Internet for a lot of information.
Two: the queue of PHP
In PHP, the queue behaves as an array. The first element in the array is the head of the team, the last element as the tail of the queue, so you can manipulate the queues.
The result is
There are many well-packaged classes on the web that can be used directly.
Array_push: Presses one or more cells into the end of the array (into the stack)
Array_unshift: Inserting one or more cells at the beginning of an array
Array_pop: POPs the last cell of the array (out of the stack)
Array_shift: Moves the cell at the beginning of the array to a group
Three: Ruby Starling
Starling is a lightweight persistent server that supports the Memcache protocol. Starling is to make it easy to create network access queues or multiple queues, which means asynchronous worker processes between multipoint and multiple machines. It is the famous micro-blogging site that Twitter developed to handle a large number of queue messages, as well as to keep the service responsive. Starling has been used in the production environment, not just by Twitter, but also by the use of fiveruns. Fiveruns even made improvements based on its own application.
Starling and Memcache use a protocol that is just a different port. Starling uses 22122 ports and Memcache uses 11211 ports.
Rubytar XZVF ruby-1.9.1-p0.tar.gzcd ruby-1.9.1-p0./configure--prefix=/usr/local/huiyangrubymake make install Gemtar- ZXVF rubygems-1.3.6.tgzcd rubygems-1.3.6ruby setup.rb starlinggem Install memcache-client starlingstarlingstarling &//Background execution starling_top//view PS information |
Then you can use the queue to do your own thing. Starling and Memcache usage, they work better together.
Use Memcache::addserver to establish a memcache connection pool. He is different from connect with Pconnect He is in the request is only connected, no port connection.
Memcache::connect--Opens a connection to Memcache.
Memcache::pconnect--Open a long connection to Memcache.
Memcache::close--Closes a Memcache connection.
Memcache::set--Save the data to the Memcache server.
Memcache::get--Extracts a data stored on the Memcache server.
Memcache::replace-Replaces an item that already exists on the Memcache server (functionally similar to 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 state of the current Memcache server running.
Four: Zhang Yi works Httpsqs
The HTTPSQS (HTTP Simple queue Service) is an HTTP Get/post protocol-based lightweight, open-source, easy-to-use Message Queuing service that uses the B+tree Key/value database of the Tokyo Cabinet to make persistent storage of data.
Interested can see the URL: http://blog.s135.com/httpsqs_1_2/
V: Application of queues
Queues are a good way to handle data transfer and storage 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 asynchronously. In addition, the slow processing logic, the processing logic with concurrent quantity limit, can be processed in the background through message queue, such as FLV video conversion, sending SMS, sending e-mail, etc. (Wen/Hou Huiyang Phper.yang)
http://www.bkjia.com/PHPjc/322421.html www.bkjia.com true http://www.bkjia.com/PHPjc/322421.html techarticle One: The concept of a queue, the data structure queue, is a linear table that is constrained by operations. Only one end of the table is allowed to be inserted, while the other end is a linear table that deletes elements. ...