1

I have a script for chat auto respond that uses while() to run, so it runs forever until it dies.
I want to be able to make it send a 'PING' message once every 3 minutes but still can do 'AUTO RESPOND' each message received.
The trouble is if i am using sleep(180) function for looping 'PING' message every 3 minute will make the 'AUTO RESPOND' every message be stop responding message because the script get sleep with sleep(180) function.
So what solution to make the script can do looping 'PING' message every 3 minutes but still can do 'AUTO RESPOND' every message at the same time.

What is possible ?
Did someone can help me with based on my script below ?

$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;  
 }  
}  
}  

0 Answers0