$hasmsg = true; if (!isset($sentmsgs)) $sentmsgs = array(); $now = microtime(true); while (count($sentmsgs) > 0 and $sentmsgs[0] < $now) array_shift($sentmsgs); logmsg('Number of sent messages the last 4 seconds: '.count($sentmsgs), DEBUG_DEBUG); if (count($sentmsgs) < 4) { if (!($msg = array_shift($messages[0]))) if (!($msg = array_shift($messages[1]))) $hasmsg = false; if ($hasmsg) { $lastsend = time(); $sentmsgs[] = $now + 2 + 2 * count($sentmsgs); issuecommand($msg[0], $msg[1]); } }