amqp php extension install

How to install amqp on windows

I am having this error while installing pecl/amqp

when I type in the command line: pear install pecl/amqp

config variable php_suffix does not match
ERROR: The DSP amqp.dsp does not exist.

I need to install this so that I can use amqp ( RabbitMQ ) on php.

5 Answers 5

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 the information on the php.net page is outdated

To install do like this:

All this according to the post on the blog I found here.

UPDATE

I updated some of the information above. The blog post is from 2013, and only mentioning older versions, but it is anyway a nice guide to the steps you need to take. Since then newer versions are available so be aware there are some slight differences in the process (mainly version numbers) if you want to install a newer version.

This works for me in PHP 7.1, and amqp 1.9.4 for Windows.

On Windows 10, build 19041 (2004 update), 64-bit.

Using Xampp with PHP 7.4.8.

If you’ve got PHP running as a service with Apache, restart Apache. If you’re using it via CLI (e.g. via Bash and/or Symfony CLI server) then you’re already good to go.

Источник

Amqp php extension install

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

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).

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.

Nested header arrays may contain only string values.

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

How to report a problem

Things to check before reporting a problem

Some of them, the list is not complete.

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 is ready to help find memory-related problems if you export TEST_PHP_ARGS=-m before running tests.

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

. 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

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

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.

About

PHP extension to communicate with any AMQP compliant server

Источник

1. Enter the PHP container in docker

Note: If the following error is reported, run the command

Resolve the wrong command:

The installation is successful as shown below:

3. Run and install amqp mirror [ Note: after amqp is the version number, if the installation fails without the version number, you can try 】

4. The installation is complete as follows

5. Solve the problem of not being added to php.ini

1. Check the location of php.ini

2. Enter the file directory where php.ini is located, and check whether the php.ini file exists

3. Select and enter the conf.d folder to view the image

4. Use the vi command to create an amqp.ini file and add extension=amqp.so to the file

5. Check whether the file is created successfully

6. Copy the folder to ext

7. Install the extension

Note: The following error may be reported at this time, but when you check phpinfo(), you will find that the extension has been installed successfully

Источник

How to Install AMQP PHP Extension and RabbitMQ Client on Linux

To connect to RabbitMQ message queue server, you can write your client program using various programming languages. Currently you can write client using C#, erlang, java, perl, PHP, python, and ruby.

This tutorial explains how to install and configure RabbitMQ client library and AMQP PHP extension.

Once you get AMQP PHP extension installed, you can write PHP program using AMQP, which can connect to RabbitMQ server to manipulate the messages.

Part 1: Install RabbitMQ Client Library

1. Install cmake

cmake is a open source build system that is used by rabbitmq-c library. We need to install rabbitmq-c library before we install AMQP PHP extension. But, to install rabbitmq-c library, we need cmake.

From the cmake download page, scoll down to Linux i386 section and download the cmake-2.8.10.2-Linux-i386.sh file. Or, use the wget to download it on your system.

Execute the cmake-2.8.10.2-Linux-i386.sh file, which will install cmake under your current directory as shown below.

Rename the cmake directory, and verify that cmake is installed properly.

2. Download RabbitMQ Client

First install the librabbitmq library, which is required by the AMQP PHP extension.

3. Configure RabbitMQ Client

Use cmake to configure the rabbitmq client for install. Make sure to specify the PREFIX as /usr/local, where the rabbitmq client will be installed.

4. Install RabbitMQ Client

After configuring, use cmake to install rabbitmq client as shown below. This will install librabbitmq library under /usr/local. Partial output is shown below.

5. Verify RabbitMQ Client

The library comes with an example program that you can use to verify that it works as expected.

From a terminal, do the following. This will be in a waiting state.

Open anothe rterminal, and do the following. This will send a “hello world” message to the queue.

Now go back to the first terminal that was in waiting state, where you’ll now see the “hello world” message as shown below.

Читайте также:  К чему снится есть в столовой во сне

Part 2: Install AMQP PHP Extension

You can install amqp using pecl, or you can compile from source.

To install using pecl, just do the following:

To install from source (which I prefer), follow the steps below.

6. Download AMQP PHP extension

Download the latest stable version of AMQP PHP extension. The current stable version is 1.0.10

7. Configure AMQP

Execute phpize and configure as shown below.

8. Install AMQP

Install AMQP using make and make install as shown below. Partial output is shown.

9. Modify php.ini and add AMQP Extension

Locate the php.ini file on your system and add the following line to it.

10. Verify AMQP PHP Extension

Create the following test page that will display phpinfo, and place this under your Apache’s htdocs.

Now, if you call test.php from your browser, you’ll see that AMQP PHP extension is displayed on the page as shown below. Now, you can write AMQP calls in your PHP code to talk to RabbitMQ server.

Источник

Amqp php extension install

This library is a pure PHP implementation of the AMQP 0-9-1 protocol. It’s been tested against RabbitMQ.

The library was used for the PHP examples of RabbitMQ in Action and the official RabbitMQ tutorials.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

The package is now maintained by Ramūnas Dronga, Luke Bakken and several VMware engineers working on RabbitMQ.

Supported RabbitMQ Versions

Starting with version 2.0 this library uses AMQP 0.9.1 by default and thus requires RabbitMQ 2.0 or later version. Usually server upgrades do not require any application code changes since the protocol changes very infrequently but please conduct your own testing before upgrading.

Supported RabbitMQ Extensions

Since the library uses AMQP 0.9.1 we added support for the following RabbitMQ extensions:

Extensions that modify existing methods like alternate exchanges are also supported.

AMQProxy is a proxy library with connection and channel pooling/reusing. This allows for lower connection and channel churn when using php-amqplib, leading to less CPU usage of RabbitMQ.

Ensure you have composer installed, then run the following command:

Then you need to use the relevant classes, for example:

With RabbitMQ running open two Terminals and on the first one execute the following commands to start the consumer:

Then on the other Terminal do:

You should see the message arriving to the process on the other Terminal

Then to stop the consumer, send to it the quit message:

If you need to listen to the sockets used to connect to RabbitMQ then see the example in the non blocking consumer.

Please see CHANGELOG for more information what has changed recently.

To not repeat ourselves, if you want to learn more about this library, please refer to the official RabbitMQ tutorials.

Multiple hosts connections

If you have a cluster of multiple nodes to which your application can connect, you can start a connection with an array of hosts. To do that you should use the create_connection static method.

This code will try to connect to HOST1 first, and connect to HOST2 if the first connection fails. The method returns a connection object for the first successful connection. Should all connections fail it will throw the exception from the last connection attempt.

See demo/amqp_connect_multiple_hosts.php for more examples.

and then send the batch like this:

When do we publish the message batch?

Читайте также:  обучение персонала по оказанию первой медицинской помощи

Let’s say our program needs to read from a file and then publish one message per line. Depending on the message size, you will have to decide when it’s better to send the batch. You could send it every 50 messages, or every hundred. That’s up to you.

Optimized Message Publishing

Another way to speed up your message publishing is by reusing the AMQPMessage message instances. You can create your new message like this:

Truncating Large Messages

AMQP imposes no limit on the size of messages; if a very large message is received by a consumer, PHP’s memory limit may be reached within the library before the callback passed to basic_consume is called.

Note that all data above the limit is read from the AMQP Channel and immediately discarded, so there is no way to retrieve it within your callback. If you have another consumer which can handle messages with larger payloads, you can use basic_reject or basic_nack to tell the server (which still has a complete copy) to forward it to a Dead Letter Exchange.

Some RabbitMQ clients using automated connection recovery mechanisms to reconnect and recover channels and consumers in case of network errors.

Since this client is using a single-thread, you can set up connection recovery using exception handling mechanism.

Exceptions which might be thrown in case of connection errors:

Some other exceptions might be thrown, but connection can still be there. It’s always a good idea to clean up an old connection when handling an exception before reconnecting.

For example, if you want to set up a recovering connection:

This code will reconnect and retry the application code every time the exception occurs. Some exceptions can still be thrown and should not be handled as a part of reconnection process, because they might be application errors.

This approach makes sense mostly for consumer applications, producers will require some additional application code to avoid publishing the same message multiple times.

This was a simplest example, in a real-life application you might want to control retr count and maybe gracefully degrade wait time to reconnection.

You can find a more excessive example in #444

If you have installed PCNTL extension dispatching of signal will be handled when consumer is not processing message.

To disable this feature just define constant AMQP_WITHOUT_SIGNALS as true

If you have installed PCNTL extension and are using PHP 7.1 or greater, you can register a signal-based heartbeat sender.

If you want to know what’s going on at a protocol level then add the following constant to your code:

To run the publishing/consume benchmark type:

To successfully run the tests you need to first have a stock RabbitMQ broker running locally.Then, run tests like this:

Please see CONTRIBUTING for details.

If you still want to use the old version of the protocol then you can do it by setting the following constant in your configuration code:

Providing your own autoloader

If for some reason you don’t want to use composer, then you need to have an autoloader in place fo the library classes. People have reported to use this autoloader with success.

Below is the original README file content. Credits goes to the original authors.

PHP library implementing Advanced Message Queuing Protocol (AMQP).

The library is port of python code of py-amqplib http://barryp.org/software/py-amqplib/

It have been tested with RabbitMQ server.

For discussion, please join the group:

For bug reports, please use bug tracking system at the project page.

Источник

Образовательный портал