In modern web solutions socket servers and communication with them becomes more and more necessary. Coming from an PHP background and wanting (or even needing - as per requirement - ) to stay within this PHP environment, there are probably plenty solutions to setup a (Web-)Socket server, if you don't want to develop it all on your on.

One solution that I use is Ratchet ( which is built upon ReactPHP and can easily be included in your project via Composer.

The problem with this is that it provides a WebSocket (or some other types of socket servers), however you may want your PHP application to trigger/broadcast messages through this WebSocket to all subscribed clients. To make this happen you will need ZeroMQ to interact with a running PHP script (the script which runs in infiinite loop to serve as a SocketServer).

ZeroMQ does have implementations in dozens of programming languages as well as PHP. You will need to install ZeroMQ and also its PHP bindings. Theoretically the installation of those two should be fairly easy. However it is definitely not. If you search the internet for this task you will find hundreds and more posts, with people having a hard time with this.

No guide seemed to work for me, so I just wanted to post the final solution - which by the way - just took two days to find out.

The installation of ZeroMQ isn't the problem. It works like stated in the official docs. The problem however is the installation of the PHP bindings. They should be installable through pecl by just running pecl install zmq-beta as stated in the ZeroMQ Wiki. This always ended in an PHP fatal error in my php:7.4-cli container. In the end the trick was to manually checkout the repo from github and make it yourself.

So this is the final dockerfile that does the job:

FROM php:7.4-cli
WORKDIR /usr/src/myapp
RUN apt-get update;
RUN apt-get install -y libzmq3-dev git;
RUN git clone git://; \
cd php-zmq; \
phpize && ./configure; \
make; \
make install;
RUN echo "extension=zmq" >> /usr/local/etc/php/conf.d/zmq.ini;

If you like you may remove git after the installation.

For some people this seems to be trivial, however since it took me two days and I don't want to invest this time again, I'm keeping it up here to have a source for copying if I ever need it again.