[zeromq-dev] Newbie Question: php-zmq and the "Divide and Conquer" Example - "Failed to bind the ZMQ: Address already in use"

Kermode Bear kermodebear at gmail.com
Tue Jan 4 18:20:15 CET 2011


Hello,

I have just started working with ZeroMQ and thought that it would be a great
fit for a personal project of mine that is being written in PHP. In order to
learn the ins and outs, I thought it would be a good idea to start by
translating the C examples into PHP.

I am currently working on the "Divide and Conquer" example given in the
ZeroMQ guide. It is my understanding that:
1. The Ventilator is started;
2. One or more Workers are started;
3. The Sink is started;
4. The Ventilator is then told to send messages to the Workers.

When porting the code directly, the Worker is to
bind('tcp://localhost:5557'). However, this fails on my system with the
message:
ZMQSocketException: Failed to bind the ZMQ: No such device

I'm going to guess that this is a problem with my local system, but when I
ping localhost, or use ftp/ssh/etc., it resolves to 127.0.0.1 as it should
and I hit my local box without an issue. I'm perplexed here.

So, I decided to try to use 127.0.0.1 directly instead of localhost. When I
do this, I receive the following error message:
ZMQSocketException: Failed to bind the ZMQ: Address already in use in
/home/kermode/zmq/example/worker.php on line 4

I am currently running Ubuntu Server 8.04 (2.6.24-19-server), ZeroMQ 2.0.10,
and the master trunk of php-zmq.

Below are two simplified versions of the code that are capable of producing
both errors. Change 'tcp://localhost:5557' to 'tcp://127.0.0.1:5557' in
worker.php for the second error.

ventilator.php:
<?php
$context = new ZMQContext();
$sender  = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$sender->bind('tcp://*:5557');
$sender->send('This is a test message.');
?>

worker.php:
<?php
$context = new ZMQContext();
$recv    = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$recv->bind('tcp://localhost:5557');
var_dump($recv->recv());
?>

Start the ventilator process, then start the worker process to see things
explode.

Where am I breaking things? The examples from the php-zmq site seem to work
without any issues, so I'm certain that the problem is me.

Thank you very much,
KBear
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110104/5d9bb63c/attachment.htm>


More information about the zeromq-dev mailing list