Search code examples
phpzeromqratchetreactphp

React warning "stream_select(): cannot represent a stream of type ZMQ_FD as a select()able descriptor"


I'm trying to use Ratchet for the first time and am following the push tutorial.

I have the following code in push-server.php:

namespace app\ratchet;
require_once(__DIR__ . '/../common_functions.php'); // my autoloader
require __DIR__ . '/../../vendor/autoload.php'; // composer autoloader

use app\ratchet\Pusher;

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

$loop   = \React\EventLoop\Factory::create();
$pusher = new Pusher;

// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new \React\ZMQ\Context($loop);
$pull = $context->getSocket(\ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:8184'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new \React\Socket\Server($loop);
$webSock->listen(8185, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new \Ratchet\Server\IoServer(
    new \Ratchet\Http\HttpServer(
        new \Ratchet\WebSocket\WsServer(
            new \Ratchet\Wamp\WampServer(
                $pusher
            )
        )
    ),
    $webSock
);

$loop->run();

When I run the file I get the following warning

Warning: stream_select(): cannot represent a stream of type ZMQ_FD as a select()able descriptor in [...]\vendor\react\event-loop\StreamSelectLoop.php on line 255

Call Stack:
    0.0000     237608   1. {main}() [...]\app\ratchet\push-server.php:0
    0.0130    1400696   2. React\EventLoop\StreamSelectLoop->run() [...]\app\ratchet\push-server.php:36
    0.0130    1401688   3. React\EventLoop\StreamSelectLoop->waitForStreamActivity() [...]\vendor\react\event-loop\StreamSelectLoop.php:201
    0.0130    1402240   4. React\EventLoop\StreamSelectLoop->streamSelect() [...]\vendor\react\event-loop\StreamSelectLoop.php:221
    0.0130    1402384   5. stream_select() [...]\vendor\react\event-loop\StreamSelectLoop.php:255

The referenced line in \vendor\react\event-loop\StreamSelectLook.php is:

return stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);

I have never used Ratchet or ZeroMQ before and am struggling to understand what the problem is. I can't find anything helpful on Google when searching for this.

I'm running WampServer x 64 on Windows 7 x 64. I followed this guide on how to install ZMQ.

Here are some debugging screenshots:

enter image description here

enter image description here

What's causing this problem and how do I fix it?


Solution

  • After about five hours of trying to figure out the solution to this problem, I tried installing the 32-bit version of WampServer based on a comment I read somewhere and the problem is fixed. So it appears the stream_select() issue is caused by a problem with WampServer.

    I'll leave this question here because I'm sure someone will run into the same problem at some point and hopefully this will save them a lot of time.