Install and use the PHP queue service HTTPSQS instance-PHP source code

Source: Internet
Author: User
HTTPSQS (HTTPSimpleQueueService) is a lightweight open-source Simple Message Queue Service Based on HTTPGETPOST protocol. It uses the TokyoCabinet B + TreeKeyValue database for persistent data storage HTTPSQS (HTTP Simple Queue Service) is a lightweight open-source simple Message Queue Service Based on http get/POST protocol. It uses the B + Tree Key/Value database of Tokyo Cabinet for persistent data storage.

Script ec (2); script

HTTPSQS (HTTP Simple Queue Service) is a Simple Queue Service Based on http get/POST requests.

Install and use the PHP queue service HTTPSQS


The Queue is also known as the First In First Out table (First In First Out), that is, the elements that First enter the Queue are extracted from the Queue. One end of the element is called the "head of the team", and the other end of the element is called the "end of the team ". Message Queue can be used to process data transmission and storage asynchronously. When you insert data frequently into the database and submit data frequently to the search engine, Message Queue can be used for asynchronous insertion. In addition, you can also put slow processing logic and limited number of concurrent processing logic in the background through message queues for processing, such as FLV video conversion, sending SMS messages, and sending email, that is, asynchronous requests are implemented.

HTTPSQS has the following features:

● Very simple, based on the http get/POST protocol. PHP, Java, Perl, Shell, Python, Ruby, and other programming languages that support HTTP protocol can be called.
● Very fast. The speed of inbound and outbound queues exceeds 10000 times/second.
● High concurrency, supporting tens of thousands of concurrent connections, C10K is not a problem.
● Supports multiple queues.
● A single queue supports up to 1 billion queues.
● Low memory consumption, massive data storage, and storage of dozens of GB of data requires less than MB of physical memory buffer.
● You can easily modify the maximum number of queues for a single queue without stopping the service.
● You can view the status of a queue in real time (including the inbound queue location, outbound queue location, number of unread queues, and maximum number of queues ).
● You can view the content of the specified queue ID (queue point), including the content of the queue that has not been output or has been output.
● Multi-character set encoding is supported when you view queue content.
● The Source Code cannot exceed 800 lines, which is suitable for secondary development.

HTTPSQS usage example:

// Generate a statement
Public function create_dzd ()
{
$ Sl_id = I ('get. sl_id ', '', 'intval ');
$ Sl_uid = I ('get. sl_uid ', '', 'intval ');

$ This-> send_task-> startTrans (); // start the 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 generate a statement in the background
$ 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 (array ('code' => 0, 'msg '=>' generation started! '));
} Else {
$ This-> send_task-> rollback ();
$ This-> ajaxReturn (array ('code' => 2, 'msg '=> 'Statement generation failed '));
}
} Else {
$ This-> ajaxReturn (array ('code' => 3, 'msg '=> 'Statement generation failed '));
}
}

This is a queue application that generates statement, enters the queue, and writes records to a table record. Another java script reads the queue for processing and updating records.

HTTPSQS is encapsulated in a class and called as follows:


// Initialize 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, a queue server must be installed with the queue service.

The above initialization queue also specifies an ip address and port to connect to the Queue Server to perform queue operations.

HTTPSQS Server 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/
# Note: To compile Tokyo cabinet on a 32-bit Linux operating system, use./configure -- enable-off64 instead of./configure, which can make the database file break through the limit of 2 GB.
#./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, refer to: 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.