1

I'm running a timer using react\eventloop on my ratchet wamp app. I would like to have it run hourly at 3600 seconds, but for some reason if I set the interval higher than 2147 seconds I get this warning:

Warning: stream_select(): The microseconds parameter must be greater than 0 in C
:\wamp\www\vendor\react\event-loop\StreamSelectLoop.php on line 255

What's so special about 2147 seconds? And what can I do to bypass this contraint?

The Event Handler

class Pusher implements WampServerInterface, MessageComponentInterface {   
    private $loop;
}

public function __construct(LoopInterface $loop) {
    $this->loop = $loop;

    $this->loop->addPeriodicTimer(2147, function() {
         //code   
    });
}

public function onSubscribe(ConnectionInterface $conn, $topic) {}
public function onUnSubscribe(ConnectionInterface $conn, $topic) {}
public function onOpen(ConnectionInterface $conn) {}
public function onClose(ConnectionInterface $conn) {}
public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {}
public function onPublish(ConnectionInterface $conn, $topic, $event {}
public function onError(ConnectionInterface $conn, \Exception $e) {}

The Server

$loop = Factory::create(); 

$webSock = new Server($loop);
$webSock->listen(8080, '0.0.0.0'); 

new IoServer(
    new HttpServer(
        new WsServer(
            new SessionProvider(
                new WampServer(
                    new Pusher($loop)),                 
                $sesshandler
            )
        )

    ),
    $webSock
);

$loop->run();
4

1 回答 1

1

这是因为 32 位平台上 PHP 整数的限制。

2147(秒)* 1000000(一秒内的微秒)~= PHP_INT_MAX 在 32 位平台上。在 64 位平台上,该限制约为 30 万年。

奇怪的是,React 的React\EventLoop\StreamSelectLoop调用stream_select()只带有微秒参数,而它也接受秒。也许他们应该解决这个问题。作为一种解决方法,您可以覆盖StreamSelectLoop实现,以便它$tv_sec使用stream_select().


我创建了一个拉取请求,让我们看看它是否会被接受

于 2015-02-05T05:06:17.713 回答