VPC version Wamp 2.4
1. Open OpenSSL
Modify the file configuration of PHP. ini respectively
E: \ Wamp \ bin \ apache \ apache2.4.4 \ bin \ PHP. ini
E: \ Wamp \ bin \ apache \ apache2.4.4 \ bin \ PHP. ini
PHP. ini Enabled
Extension = php_openssl.dll
2. Download composer
Https://getcomposer.org/Composer-Setup.exe
After the download is complete, click Next to install graph ......
3. Download PHP-amqplib
Https://github.com/videlalvaro/php-amqplib/archive/master.zip
Copy the phpamqplib folder to the project root directory after pressurization.
4. Create a file in the root directory: composer. JSON
{
"Require ":{
"Videlalvaro/PHP-amqplib": "2. 2 .*"
}
}
5. Run the CMD command to install PHP-amqplib:
E: \ Wamp \ bin \ PHP \ php5.4.16> E: \ Wamp \ bin \ PHP \ php5.4.16/php.exe composer
Cocould not open input file: Composer
E: \ Wamp \ bin \ PHP \ php5.4.16> PHP composer. phar
Cocould not open input file: composer. phar
E: \ Wamp \ bin \ PHP \ php5.4.16> composer update friendsofsymfony/user-bundle
Composer cocould not find a composer. JSON file in E: \ Wamp \ bin \ PHP \ php5.4.16
To initialize a project, Please create a composer. JSON file as described in
Http://getcomposer.org/"Getting started" section
Install PHP-amqplib in the project and Directory
E: \ Wamp \ www \ GX> composer update friendsofsymfony/user-bundle
Package "friendsofsymfony/user-bundle" listed for update is not installed. ignor
Ing.
Loading composer repositories with package information
Updating dependencies (including require-Dev)
-Installing videlalvaro/PHP-amqplib (v2.2.6)
Downloading: 100%
Writing lock file
Generating autoload files
6. Start the test after the environment is complete
Send. php
<? PHP
Require_once _ DIR _. '/vendor/autoload. php ';
Use phpamqplib \ connection \ amqpconnection;
Use phpamqplib \ message \ amqpmessage;
$ Connection = new amqpconnection ('192. 168.99.104 ', 192, 'Guest', 'Guest ');
$ Channel = $ connection-> channel ();
$ Channel-> queue_declare ('hello', false );
$ DATA = implode ('', array_slice ($ argv, 1 ));
If (empty ($ data) $ DATA = "Hello world! ";
$ MSG = new amqpmessage ($ data,
Array ('delivery _ mode' => 2) # Make message persistent
);
$ Channel-> basic_publish ($ MSG, '', 'Hello ');
Echo "[x] sent", $ data, "\ n ";
$ Channel-> close ();
$ Connection-> close ();
?>
Receive. php
<? PHP
Require_once _ DIR _. '/vendor/autoload. php ';
Use phpamqplib \ connection \ amqpconnection;
$ Connection = new amqpconnection ('192. 168.99.104 ', 192, 'Guest', 'Guest ');
$ Channel = $ connection-> channel ();
$ Channel-> queue_declare ('hello', false );
Echo '[*] waiting for messages. To exit press Ctrl + C', "\ n ";
$ Callback = function ($ MSG ){
Echo "[x] received", $ MSG-> body, "\ n ";
Sleep (substr_count ($ MSG-> body ,'.'));
Echo "[x] Done", "\ n ";
$ MSG-> delivery_info ['channel']-> basic_ack ($ MSG-> delivery_info ['delivery _ tag']);
};
$ Channel-> basic_qos (null, 1, null );
$ Channel-> basic_consume ('hello', '', false, $ callback );
While (count ($ channel-> callbacks )){
$ Channel-> wait ();
}
?>
7. CMD command line test:
Send message:
E: \ Wamp \ www \ GX> PHP send. php is successfully tested.
[X] The sent test is successful.
E: \ Wamp \ www \ GX> PHP send. php wamp2.4 + rabbitmq passed the test
[X] sent wamp2.4 + rabbitmq passed the test
Receive message:
E: \ Wamp \ www \ GX> PHP receive. php
[*] Waiting for messages. To exit press Ctrl + c
[X] successfully tested the stored ed.
[X] Done
[X] tested ed wamp2.4 + rabbitmq passed the test
[X] Done
This article is from the "Yanzi" blog, please be sure to keep this source http://daddysgirl.blog.51cto.com/1598612/1436412