我正在我的ratchet wamp 应用程序上使用react\eventloop 运行计时器。我想让它每小时运行 3600 秒,但由于某种原因,如果我将间隔设置为高于 2147 秒,我会收到此警告:

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

2147秒有什么特别之处?我该怎么做才能绕过这个限制?

事件处理程序

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) {}

服务器

$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();
有帮助吗?

解决方案

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

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

奇怪的是 React 的 React\EventLoop\StreamSelectLoop 来电 stream_select() 仅使用微秒参数,同时它也接受秒。也许他们应该解决这个问题。作为解决方法,您可以覆盖 StreamSelectLoop 实施,以便利用 $tv_sec 参数输入 stream_select().


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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top