使用 Ratchet php 创建一个计时器 [英] Create a timer with Ratchet php

查看:34
本文介绍了使用 Ratchet php 创建一个计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的套接字服务器的想法而苦苦挣扎.它基于棘轮 php.

I am strugling with an idea I have with my socket server. It's based on ratchet php.

我想要实现的是在某个事件之后我想设置一个计时器.当定时器结束时,通知每一个连接.当我使用 sleep 功能时,我的套接字服务器睡眠并且在那个时间不能接受任何东西.

What I want to achieve is after a certain event I would like to set a timer. When the timer is finished, to notify every connection. When I use the sleep function, my socket server sleeps and can't accept anything for that time.

你们能告诉我怎么做吗,或者有可能吗?

Can you guys please give me an idea of how to do it, or is it possible ?

推荐答案

你不应该阻塞事件循环服务器的工作...

You should never block the work of event-loop server...

要创建计时器 - 您需要联系 LoopInterface(Reactphp 库).

To create a timer - you need to contact LoopInterface (Reactphp library).

通常在服务器类(例如IOServer)中

Usually it is in the server classes (eg IOServer)

这就是创建计时器的方法:

That's how you can create a timer:

$this->loop->addPeriodicTimer($timeout, function($timer) {

});

这篇关于使用 Ratchet php 创建一个计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆