Using ZeroMQ in a PHP script inside Apache

I want to use the ZeroMQ publisher / subscriber to send data from my web application to multiple servers.

I am using Apache and PHP for a web application, my php script works as follows:

//Initialization
$context = new ZMQContext();
$publisher = $context->getSocket(ZMQ::SOCKET_PUB);
$publisher->bind("tcp://*:5556");

//Then publishing for testing:

$publisher->send("test");
$publisher->send("test");
$publisher->send("test");
$publisher->send("test");
$publisher->send("test");

For testing, I adapted the subscriber from the documentation in python:

import sys
import zmq

#  Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)

socket.connect ("tcp://localhost:5556")

# Subscribe to zipcode, default is NYC, 10001
socket.setsockopt(zmq.SUBSCRIBE, "")

print "Waiting..."
# Process 5 updates
for update_nbr in range (5):
    string = socket.recv()
    print string

All this works when I run the php script from the command line, but it doesnโ€™t work through Apache (when the script is executed through a web browser).

Is there something I have to do for my Apache configuration to get it working?

thank

Alexander

+5
source share
1 answer

It seems that the only problem was that the connection did not manage to establish.

, .

:

http://zguide.zeromq.org/page:all#Getting-the-Message-Out

+2

All Articles