[zeromq-dev] Connecting via Websockets to PHP ZeroMQ socket

Max nash12 at gmail.com
Wed Mar 28 14:45:26 CEST 2012


has anyone had success in connecting via Javascript using Websockets
to a serverside PHP ZeroMQ socket/server?

Basically I am using Rasmus server code from
which works (I changed the socket tcp address so that outside
connections are allowed). But as soon as I connect to that socket from
my Browser using a Websocket  the PHP script tells me it received a
new connection but it doesnt receive any data.

Here is the code again for receiving data:

function print_line($fd, $events, $arg) {
    static $msgs = 1;
    if($arg[0]->getsockopt (ZMQ::SOCKOPT_EVENTS) & ZMQ::POLL_IN) {
        echo "Got incoming data" . PHP_EOL;
        var_dump ($arg[0]->recv()); // here I get stuck, nothing is
read from the socket, the script just hangs
        $arg[0]->send("Got msg $msgs");

	if($msgs++ >= 10) event_base_loopexit($arg[1]);

"Got incoming data" is displayed but nothing ever is received.

I poked arount a bit using ngrep and here is what is sent over the wire:

T _webbrowser_ -> _server_ [AP]
GET / HTTP/1.1.
Host: zeromq.test:5555.
... blabla...
Pragma: no-cache.
Cache-Control: no-cache.
Upgrade: websocket.

T _server_ -> _webbrowser_ [AP]

Whats that "~" which is being returned?

I must be doing something totally wrong, so if anyone has experience
in bringing togehter websockets and PHP using ZeroMQ I would be very
interested in your thoughts. ;-)

I am using the newest stable release of ZeroMQ.

More information about the zeromq-dev mailing list