How should I use php amqp?

Source: Internet
Author: User
I installed the amqp extension of rabbitmq and php, but I don't know how to use it. I searched for the tutorial on the Internet, but I didn't quite understand it. This is send. PHP file, {code ...} this is receive. PHP file {code ...} use the browser to first access send. php is fine. Access receive again. php... I installed the amqp extension of rabbitmq and php, but I don't know how to use it. I searched for the tutorial on the Internet, but I didn't understand it too well,
This is the send. php file,

$ Conf = ['host' => 'localhost', 'Port' => '000000', 'login' => 'guest ', 'Password' => 'guest ', 'vhost' => '/']; $ connect = new \ AMQPConnection ($ conf); if (! $ Connect-> connect () {die ('connetc error');} $ message = "test message! Test message! "; $ Channel = new AMQPChannel ($ connect); $ exchange = new AMQPExchange ($ channel); $ exchange-> setName ('zblexchang '); $ queue = new AMQPQueue ($ channel); $ queue-> setName ('zblqueue '); for ($ I = 0; $ I <5; ++ $ I) {echo "Send Message :". $ exchange-> publish ($ message, 'zblqueue '). "\ n" ;}// $ channel-> commitTransaction (); // submit the transaction $ connect-> disconnect ();

This is the receive. php file.

$ Conf = ['host' => 'localhost', 'Port' => '000000', 'login' => 'guest ', 'Password' => 'guest ', 'vhost' => '/']; $ connect = new AMQPConnection ($ conf); if (! $ Connect-> connect () {die ('connetc error');} $ channel = new AMQPChannel ($ connect); $ exchange = new AMQPExchange ($ channel ); $ exchange-> setName ('zblexchange'); $ exchange-> setType (AMQP_EX_TYPE_DIRECT); // echo "Exchange Status :". $ exchange-> declare (). "\ n"; $ queue = new AMQPQueue ($ channel); $ queue-> setName ('zblqueue '); $ queue-> setFlags (AMQP_DURABLE ); // persistent echo "Message Total :". $ queue-> declare (). "\ n"; echo 'queue Bind :'. $ queue-> bind ('zblexchang', 'zblqueue '). "\ n"; echo "Message: \ n"; // while (True) {$ queue-> consume ('processmessage'); // echo 'hello '; // $ q-> consume ('processmessage', AMQP_AUTOACK); // automatic ACK response //} $ connect-> disconnect (); function processMessage ($ envelope, $ queue) {$ msg = $ envelope-> getBody (); echo $ msg. "\ n"; // process the message $ queue-> ack ($ envelope-> getDeliveryTag (); // manually send ACK response}

Use the browser to first access send. php is fine. Access receive again. php is 504 gateway timeout. Use the command line to access send. the AMQPConnection class cannot be found due to a fatal error in php. I don't know what is going on. I cannot find the installed amqp extension when using php-m, however, when using phpinfo to access through a browser, it is displayed that amqp is loaded, and the Environment is centos 7, nginx 1.6.3, php 5.6.9. What is the problem here?

Reply content:

I installed the amqp extension of rabbitmq and php, but I don't know how to use it. I searched for the tutorial on the Internet, but I didn't understand it too well,
This is the send. php file,

$ Conf = ['host' => 'localhost', 'Port' => '000000', 'login' => 'guest ', 'Password' => 'guest ', 'vhost' => '/']; $ connect = new \ AMQPConnection ($ conf); if (! $ Connect-> connect () {die ('connetc error');} $ message = "test message! Test message! "; $ Channel = new AMQPChannel ($ connect); $ exchange = new AMQPExchange ($ channel); $ exchange-> setName ('zblexchang '); $ queue = new AMQPQueue ($ channel); $ queue-> setName ('zblqueue '); for ($ I = 0; $ I <5; ++ $ I) {echo "Send Message :". $ exchange-> publish ($ message, 'zblqueue '). "\ n" ;}// $ channel-> commitTransaction (); // submit the transaction $ connect-> disconnect ();

This is the receive. php file.

$ Conf = ['host' => 'localhost', 'Port' => '000000', 'login' => 'guest ', 'Password' => 'guest ', 'vhost' => '/']; $ connect = new AMQPConnection ($ conf); if (! $ Connect-> connect () {die ('connetc error');} $ channel = new AMQPChannel ($ connect); $ exchange = new AMQPExchange ($ channel ); $ exchange-> setName ('zblexchange'); $ exchange-> setType (AMQP_EX_TYPE_DIRECT); // echo "Exchange Status :". $ exchange-> declare (). "\ n"; $ queue = new AMQPQueue ($ channel); $ queue-> setName ('zblqueue '); $ queue-> setFlags (AMQP_DURABLE ); // persistent echo "Message Total :". $ queue-> declare (). "\ n"; echo 'queue Bind :'. $ queue-> bind ('zblexchang', 'zblqueue '). "\ n"; echo "Message: \ n"; // while (True) {$ queue-> consume ('processmessage'); // echo 'hello '; // $ q-> consume ('processmessage', AMQP_AUTOACK); // automatic ACK response //} $ connect-> disconnect (); function processMessage ($ envelope, $ queue) {$ msg = $ envelope-> getBody (); echo $ msg. "\ n"; // process the message $ queue-> ack ($ envelope-> getDeliveryTag (); // manually send ACK response}

Use the browser to first access send. php is fine. Access receive again. php is 504 gateway timeout. Use the command line to access send. the AMQPConnection class cannot be found due to a fatal error in php. I don't know what is going on. I cannot find the installed amqp extension when using php-m, however, when using phpinfo to access through a browser, it is displayed that amqp is loaded, and the Environment is centos 7, nginx 1.6.3, php 5.6.9. What is the problem here?

The installed amqp extension cannot be found when php-m is used, but

This is because the amqp extension is only loaded in fpm, but not in cli Script Mode. Just configure it. As for 504, I think it is very likely that your fpm is not configured properly.

See http://segmentfault.com/a/1190000002963223

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.