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