PHP AMQP Binding Library
C Roff PHP Erlang Shell M4 ApacheConf
Latest commit 4c583d1 Aug 9, 2017 @makasim makasim committed with lstrojny Add a link to amqp interop compatible transport. (#291)
* [skip ci] Add a link to amqp interop compatible transport.

* [skip ci] Change section to "Related projects"
Permalink
Failed to load latest commit information.
provision Update vagrant box [skip ci] (#290) Jul 14, 2017
stubs Fix handling channel consumers (#284) Jul 14, 2017
tests Fix handling channel consumers (#284) Jul 14, 2017
.gitignore RM 1.7.0alpha1 Nov 11, 2015
.travis.yml Add decimal value support (#269) Mar 12, 2017
CREDITS Add Squires as contributor Dec 11, 2013
LICENSE Removing trailing whitespace Nov 14, 2012
README.md Add a link to amqp interop compatible transport. (#291) Aug 9, 2017
Vagrantfile Update vagrant box [skip ci] (#290) Jul 14, 2017
amqp.c Fix handling channel consumers (#284) Jul 14, 2017
amqp_basic_properties.c Add decimal value support (#269) Mar 12, 2017
amqp_basic_properties.h Proper support AMQP for array and timestamp types for dead lettering (#… Mar 6, 2017
amqp_channel.c Add consumer tag (#282) Jun 8, 2017
amqp_channel.h Fix segfault when reusing channels Mar 10, 2017
amqp_connection.c Update amqp_connection.c (#239) Jul 9, 2016
amqp_connection.h Proper support AMQP for array and timestamp types for dead lettering (#… Mar 6, 2017
amqp_connection_resource.c Add consumer tag (#282) Jun 8, 2017
amqp_connection_resource.h Add SSL connection support Apr 27, 2016
amqp_decimal.c Add decimal value support (#269) Mar 12, 2017
amqp_decimal.h Add decimal value support (#269) Mar 12, 2017
amqp_envelope.c Add consumer tag (#282) Jun 8, 2017
amqp_envelope.h Proper support AMQP for array and timestamp types for dead lettering (#… Mar 6, 2017
amqp_exchange.c Separate queue and exchange args to avoid side effect when changing t… Jun 12, 2017
amqp_exchange.h Proper support AMQP for array and timestamp types for dead lettering (#… Mar 6, 2017
amqp_methods_handling.c Add publisher confirms support Mar 4, 2016
amqp_methods_handling.h Add publisher confirms support Mar 4, 2016
amqp_queue.c Fix handling channel consumers (#284) Jul 14, 2017
amqp_queue.h Proper support AMQP for array and timestamp types for dead lettering (#… Mar 6, 2017
amqp_timestamp.c Fix buffer size Mar 13, 2017
amqp_timestamp.h Proper support AMQP for array and timestamp types for dead lettering (#… Mar 6, 2017
amqp_type.c Add decimal value support (#269) Mar 12, 2017
amqp_type.h Proper support AMQP for array and timestamp types for dead lettering (#… Mar 6, 2017
benchmark.php Add PHP 7 support Nov 5, 2015
composer.json Add ability to re-attach consuming callback Apr 24, 2015
config.m4 Add decimal value support (#269) Mar 12, 2017
config.w32 Add decimal value support (#269) Mar 12, 2017
package.xml Back to dev Jun 12, 2017
php5_support.h Fix handling channel consumers (#284) Jul 14, 2017
php7_support.h Fix handling channel consumers (#284) Jul 14, 2017
php_amqp.h Fix handling channel consumers (#284) Jul 14, 2017
release.php Release management Mar 12, 2017
test-report.sh Add AMQPExchange::unbind method and fix AMQPExchange::bind method Dec 18, 2014

README.md

PHP AMQP bindings Build Status

Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/rabbitmq-c)

This extension works both with PHP 5 and PHP 7 (both zts and non-zts).

Requirements:

Installation

Some systems has php-amqp extension in their repo or available via external repositories, so it is MAY be the preferable way to install.

RPM packages are available in Fedora and EPEL (for RHEL and CentOS) official repositories, see php-pecl-amqp

Fresh php-pecl-amqp and librabbitmq RPMs available via remi repo.

If you want to stay on the bleeding edge and have the latest version, install php-amqp extension from PECL or compile from sources (follow PHP official docs instruction).

Documentation

View RabbitMQ official tutorials and php-amqp specific examples.

There are also available stub files with accurate PHPDoc which may be also used in your IDE for code completion, navigation and documentation in-place.

Finally, check out the tests to see typical usage and edge cases.

Notes

  • Max channels per connection means how many concurrent channels per connection may be opened at the same time (this limit may be increased later to max AMQP protocol number - 65532 without any problem).

  • Nested header arrays may contain only string values.

  • You can't share none of AMQP API objects (none of AMQPConnection, AMQPChannel, AMQPQueue, AMQPExchange) between threads. You have to use separate connection and so on per thread.

Related libraries

Persistent connection

Limitations:

  • there may be only one persistent connection per unique credentials (login+password+host+port+vhost). If there will be an attempt to create another persistent connection with the same credentials, an exception will be thrown.
  • channels on persistent connections are not persistent: they are destroyed between requests.
  • heartbeats are limited to blocking calls only, so if there are no any operations on a connection or no active consumer set, connection may be closed by the broker as dead.

Developers note: alternatively for built-in persistent connection support raphf pecl extension may be used.

How to report a problem

  1. First, search through the closed issues and stackoverflow.com.
  2. Submit an issue with short and definitive title that describe your problem
  3. Provide platform info, PHP interpreter version, SAPI mode (cli, fpm, cgi, etc) extension is used in, php-amqp extension version, librabbitmq version, make tools version.
  4. Description should provide information on how to reproduce a problem (gist is the most preferable way to include large sources) in a definitive way. Use Vagrant to replicate unusual environments.
  5. If stack trace is generated, include it in full via gist or the important part (if you definitely know what you are doing) directly in the description.

Things to check before reporting a problem

Some of them, the list is not complete.

  1. You are running on correct machine in correct environment and your platform meets your application requirement.
  2. librabbimq is installed and discoverable in your environment so php-amqp extension can load it.
  3. php-amqp extension present in system (find amqp.so or amqp.dll if you are on windows), it is loaded (php --ri amqp produced some info), and there are no underlying abstraction that MAY emulate php-amqp work.
  4. You hav correct RabbitMQ credentials.
  5. You are using the latest php-amqp, librabbitmq, RabbitMQ and sometimes PHP version itself. Sometimes your problem is already solved.
  6. Other extensions disabled (especially useful when PHP interpreter crashes and you get stack trace and segmentation fault).

Development

There is a Vagrant environment with pre-installed software and libraries necessary to build, test and run the php-amqp extension.

To start it, just type vagrant up and then vagrant ssh in php-amqp directory.

Services available out of the box are:

Additional tools are pre-installed to make development process as simple as possible:

valgrind

Valgrind is ready to help find memory-related problems if you export TEST_PHP_ARGS=-m before running tests.

phpbrew

phpbrew waits to help you to test extension on various PHP versions. phpbrew install 5.6 +debug+default+fpm is a nice start. To switch to some version just use phpbrew switch <version>.

To start php-fpm just run phpbrew fpm start (don't forget to run sudo service stop php5-fpm befor).

This development environment out of the box ready for php-fpm and cli extension usage, if need to test it when php used as apache module, refer to Apache2 support on phpbrew wiki. Keep in mind that +apxs2 conficts with +fpm and it is a bit tricky to specify which libphp .so will be loaded.

tshark

tshark - Dump and analyze network traffic

... TShark is able to detect, read and write the same capture files that are supported by Wireshark.

To use it you probably have to set network privileges for dumpcap first(see Platform-Specific information about capture privileges Wireshark docs page and running wireshark “Lua: Error during loading” SO question):

sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/dumpcap

To start capturing, run tshark -i lo to see output in terminal or tshark -i lo -w capture.log to save capture and analyze it later (even with AMQP protocol Wireshark plugin). You may filter AMQP packages using -Y amqp attribute, just give a try - tshark -i lo -Y amqp.

NOTE: -w provides raw packet data, not text. If you want text output you need to redirect stdout (e.g. using '>'), don't use the -w option for this.

Configuring a RabbitMQ server

If you need to tweek RabbitMQ server params use default config rabbitmq.config.example (raw) from official RabbitmMQ repo, so it may looks like sudo curl https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/master/docs/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config

To reset RabbitMQ application run in CLI (as privileged user) rabbitmqctl stop_app && rabbitmqctl reset && rabbitmqctl start_app.

Keeping track of the workers

It is a good practice to keep php processes (i.e workers/consumers) under control. Usually, system administrators write their own scripts which ask services about current status or performs some desired actions. Usually request is sent via UNIX signals.
Because amqp consume method is blocking, pcntl extension seems to be useless.

php-signal-handler extension uses signal syscall, so it will work even if blocking method was executed. Some use cases are presented on extension's github page and examples are available here. Note, PHP 5 only.