问题
I have RabbitMQ running on one of our servers and am trying to connect to it via PHP. I am developing on a Windows7 machine and my first line of code reads: $cnn = new AMQPConnection();
It gives me the error: Fatal error: Class 'AMQPConnection' not found in
I know that it is something that I need to install but what is it ? I am new to PHP so a little help would be nice.
Ps: I can connect to the RMQ server via the RabbitMQ admin web interface.
Thank you Jack
回答1:
I am developing on a Windows7 machine
You may be out of luck using that specific code. That class is from the PECL aqmp extension. Inside the installation instructions, it states:
Note to Windows users: This extension does not currently support Windows since the librabbitmq library does not yet support Windows.
You will want to use another library to speak to your message queue instead.
回答2:
Installation guide for php_amqp 1.4.0 (Stable version):
- Download proper package for your php version from https://pecl.php.net/package/amqp/1.4.0/windows
- Unpack php_amqp.dll to X:/php/ext/ directory
- Unpack rabbitmq.1.dll to X:/Windows/system (not system32) directory
- Modify php.ini file and add "extension=php_amqp.dll" line at the end of extensions list
- Verify module installation by executing command "X:/php/php.exe -m" in command line
- Restart webserver
回答3:
The rabbitmq-c library supports windows now, and the php_amqp pecl extension builds on windows as well. The documentation just hasn't been updated, nor are there any official binary builds in the wild. However, I managed to get them to build and have some 32 bit dll's available for download here:
http://www.nathanjohnson.info/?p=77
回答4:
@ AMQP installation php.net:
Note to Windows users: This extension does not currently support Windows since the librabbitmq library does not yet support Windows.
But here at RabbitMQ website is a windows installer...
Apparently this php.net page is outdated
To install do like this:
- Download the correct package for your php from this official PECL amqp 1.4.0 page
- unzip
- add
amqp.dll
to your phpext
folder - add
rabbitmq.1.dll
to your windows system 32 folder.
This according to the post on the blog I found here i think it is from the same @NathanJohnson who posted also here.
回答5:
How I got it working:
My System Config: Win 7 Pro, (x64) XAMPP running PHP 5.6(x86)
Follow instruction from here to install RabbitMQ:
https://www.rabbitmq.com/install-windows.html
Now download compatible extension from here
https://pecl.php.net/package/amqp/1.4.0/windows
in my case it is "5.6 Thread Safe (TS) x86"
Now from zip file (php_amqp-1.4.0-5.6-ts-vc11-x86.zip) downloaded copy dll "php_amqp.dll" to your php extension folder in my case it is "xampp/php/ext" and copy dll "rabbitmq.1.dll" to "Windows\system" directory.
now register your php_amqp dll in php.ini file as "extension=php_amqp.dll"
now restart apache.
Done. Now you should not get AMQPConnection not found exception.
来源:https://stackoverflow.com/questions/13776164/connect-to-rabbitmq-from-php-windows