I have my websocket server up and running, and for my own use I want to get back a list of the connected when I execute a static PHP script.
My PHP script pull.php
:
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_REQ);
$socket->connect("tcp://localhost:5552");
$socket->send('data');
$test = $socket->recv();
var_dump($test);
Then on my server script:
<?php
require './vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new MyApp\Pusher;
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_REP);
$pull->bind('tcp://127.0.0.1:5552');
$pull->on('message', array($pusher, 'onPull'));
$pull->recv();
$pull->send('response');
$webSock = new React\Socket\Server($loop);
$webSock->listen(8080, '0.0.0.0');
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
$pusher
)
),
$webSock
);
$loop->run();
So when my server script is running, I then run pull.php
. This works, and sends me back the response
text which I var_dump
out. However, if I then go and reload my pull.php
script, it just hangs. I've no idea why, I am assuming here that somewhere down the line it's not telling the other party that it has received the data and thus can't send another request.
Also, my $pull->on('message', array($pusher, 'onPull'));
currently sends the data into my onPull()
method in my Pusher class. At the moment I just return nothing, but if I return some data how do I get this back to the requester?
You should add the code from your
Pusher
class so we can see theonPull
method... this looks like it is still mostly yourpush/pull
code rather thanreq/rep
, which may throw some things off (for other's reference, his first question which included some indication of his use ofpush/pull
, is here)However, I think I see the issue (comments in-line):
I don't think you want Ratchet or Websockets at all here, you just want to talk to a ZMQ client, correct? So, pull that code out. What you most likely want instead is to define your
on-message
handler to handle the request and send a response. Try the following (this is based off of a very little research intoReact
, where I couldn't find areq/rep
example, so if this doesn't work then let me know)