Installation and usages of PHP queue service Httpsqs

Source: Internet
Author: User
Tags character set

HTTPSQS (HTTP Simple queue Service) is an HTTP Get/post request based on a straightforward queue.

Installation and use of the PHP queue service Httpsqs


The queue is also called a first-in first-out table (first-in-out), which is the element that enters the queue first and is taken out of the queue. Add the element to the end of the "Team head", take out the element is called "Team tail." Message Queuing enables you to asynchronously process data transfer and storage, and when you frequently insert data into the database and submit data to the search engine frequently, you can take Message Queuing to insert it asynchronously. In addition, slower processing logic, concurrency-limiting processing logic, and the use of Message Queuing in background processing, such as FLV video conversion, sending SMS, sending e-mail, etc., are also implemented to implement asynchronous requests.

HTTPSQS has the following characteristics:

Very simple, based on the HTTP Get/post protocol. PHP, Java, Perl, Shell, Python, Ruby, and other programming languages that support HTTP protocols can be invoked.
Very fast, into the queue, out of the queue speed of more than 10,000 times/sec.
High concurrency, support tens of thousands of concurrent connections, c10k is not a problem.
Supports multiple queues.
The maximum number of queues supported by a single queue is up to 1 billion.
Low memory consumption, massive data storage, storing dozens of GB of data requires less than 100MB of physical memory buffers.
You can easily modify the maximum number of queues for a single queue without stopping the service.
You can view the status of the queue in real time (into queue position, out queue location, unread queue count, maximum number of queues).
You can view the contents of the specified queue ID (queue point), including the contents of the queue that are not out or out.
Multiple character set encoding is supported when viewing the contents of a queue.
The source code does not exceed 800 lines, and is suitable for two times development.

Httpsqs Use Example:

Generate the statement
Public Function Create_dzd ()
{
$SL _id = I (' get.sl_id ', ', ', ' intval ');
$SL _uid = I (' Get.sl_uid ', ', ', ' intval ');

$this->send_task->starttrans ()//Open transaction

$data [' st_params '] = $SL _id;
$data [' st_seller_id '] = $SL _uid;
$data [' st_type '] = 3;
$data [' st_add_time '] = time ();
$data [' st_success '] = 1;//1 background generation of statements
$data [' st_is_compelete '] = 0;
$data [' st_ip '] = get_client_ip (1);
$id = $this->send_task->add ($data);
if ($id) {
$httpsqs = $this->gethttpsqs ();
$name = Self::export_record;
$rs = $httpsqs->put ($name, $id);
if ($rs) {
$this->send_task->commit ();
$this->ajaxreturn (' Code ' =>0, ' msg ' => ' has begun to build! '));
}else{
$this->send_task->rollback ();
$this->ajaxreturn (Array (' Code ' =>2, ' msg ' => ' generate statement failure '));
}
}else{
$this->ajaxreturn (Array (' Code ' =>3, ' msg ' => ' generate statement failure '));
}
}

This is the application of a queue, generating statements, entering queues, and writing records to a single table record. Another Java script reads the queue, processes it, and updates the record.

The HTTPSQS is encapsulated in a class that is called when called:


Initializing the queue service
Private Function Gethttpsqs ()
{
Import ("COM. Httpsqs ");
$httpsqs = new Httpsqs ("192.168.1.8", 1218, "DAFADSFASFSADFSA", ' utf-8 ');
return $HTTPSQS;
}
However, to use HTTPSQS, you must have a queue server, which has a queue service installed.

The above initialization queue, also specifies the IP, port, to connect the queue Server in order to do the operation of the queue.

Httpsqs Server-Side installation method:


Ulimit-shn 65535

wget http://httpsqs.googlecode.com/files/libevent-2.0.12-stable.tar.gz
Tar zxvf libevent-2.0.12-stable.tar.gz
CD libevent-2.0.12-stable/
./configure--prefix=/usr/local/libevent-2.0.12-stable/
Make
Make install
Cd.. /

wget http://httpsqs.googlecode.com/files/tokyocabinet-1.4.47.tar.gz
Tar zxvf tokyocabinet-1.4.47.tar.gz
CD tokyocabinet-1.4.47/
./configure--prefix=/usr/local/tokyocabinet-1.4.47/
#注: Compile Tokyo Cabinet on a 32-bit Linux operating system, use the./configure--enable-off64 instead of./configure, you can make the database file break through the 2GB limit.
#./configure--enable-off64--prefix=/usr/local/tokyocabinet-1.4.47/
Make
Make install
Cd.. /

wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gz
Tar zxvf httpsqs-1.7.tar.gz
CD httpsqs-1.7/
Make
Make install
Cd.. /
More specific server-side HTTPSQS Queue Service installation and compilation, reference: https://code.google.com/p/httpsqs/

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.