我有一个用于聊天自动响应的脚本,它使用 while() 来运行,所以它会永远运行直到它死掉。
我希望能够让它每 3 分钟发送一次“PING”消息,但仍然可以对收到的每条消息进行“自动响应”。
问题是,如果我使用 sleep(180) 函数每 3 分钟循环一次“PING”消息,则会使“AUTO RESPOND”每条消息都停止响应消息,因为脚本通过 sleep(180) 函数进入睡眠状态。
那么有什么解决方案可以让脚本每 3 分钟循环一次“PING”消息,但仍然可以同时对每条消息进行“自动响应”。
什么是可能的?
有人可以根据下面的脚本帮助我吗?
$this->connect();
while(!$this->isDisconnected()) {
$starts = $this->processUntil(array('message', 'session_start'));
foreach($starts as $go) {
switch($go[0]) {
case 'session_start':
$this->presence($status="Just Online !!!", $show="online");
break;
case 'message':
$filter = $show="online";
if($new['from'] == $filter) {
$sender = explode('@', $new['from']);
$this->message($new['from'], $body="AUTO RESPOND MESSAGE: Sorry $sender[0] Iam Not Here Right Now.", $type="chat");
}
$the_time = time();
$interval = 3*60;
while(true) {
if ($the_time + $interval >= time()) {
$this->message($myself, $body="PING !!!", $type="chat");
$the_time = time();
}
}
break;
}
}
}