"Message Queuing" rabbitmq+php implementation

Source: Internet
Author: User
Tags autoload install php rabbitmq

This article link: http://www.cnblogs.com/aiweixiao/p/7374249.html

Document Outline:

Scan attention to the public number

1. "Download and install"

1) github:https://github.com/php-amqplib/php-amqplib

2) "Environment preparation":

Install php rabbitmq PHP extension installation, dependent on the Erlang environment

Reference Document: Http://www.cnblogs.com/chunguang/p/5634342.html

3) "Dependency Loading of Classes": We recommend using composer implementation,

Composer Introductory 4) "Tutorial": Official Tutorial link Address: http://www.rabbitmq.com/tutorials/tutorial-one-php.html

5) test Script:

-Use the official demo:

Open a subscriber window $ cd PHP-amqplib/demo$ php amqp_consumer. PHP opens a Publisher window $ cd PHP-amqplib/demo$ php amqp_publisher. php some text to publish

--Using third-party scripting http://blog.csdn.net/u014071426/article/details/53649226

1 //referencing the required files2 require_once__dir__. '/vendor/autoload.php '; 3  Usephpamqplib\connection\amqpstreamconnection; 4  UsePhpamqplib\message\amqpmessage; 5 //establishes a connection channel that declares a queue that can send messages Hello6 $connection=NewAmqpstreamconnection (' localhost ', 5672, ' guest ', ' guest '); 7 $channel=$connection-channel (); 8 $channel->queue_declare (' Hello ',false,false,false,false); 9   Ten //define a message with the message content Hello world!  One $msg=NewAmqpmessage (' Hello world! ');  A $channel->basic_publish ($msg, ', ' Hello ');  -    - //print a message after sending to tell the person who posted the message: Send successfully the Echo"[x] Sent ' Hello world! ' \ n ";  - //Close Connection - $channel-Close ();  - $connection->close ();
View Code
1     require_once__dir__. '/vendor/autoload.php '; 2      Usephpamqplib\connection\amqpstreamconnection; 3     $connection=NewAmqpstreamconnection (' localhost ', 5672, ' guest ', ' guest '); 4     $channel=$connection-channel (); 5       6     $channel->queue_declare (' Hello ',false,false,false,false); 7       8     Echo' [*] waiting for messages. To exit Press CTRL + C ', "\ n"; 9     $callback=function($msg) {  Ten       Echo"[x] Received",$msg->body, "\ n";  One     };  A        -     //Call the $callback function when receiving a message -     $channel->basic_consume (' Hello ', ',false,true,false,false,$callback);  the        -      while(Count($channel-callbacks)) {   -         $channel-wait ();  -}

"Message Queuing" rabbitmq+php implementation

Related Article

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.