> For the complete documentation index, see [llms.txt](https://bing.gitbook.io/phper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bing.gitbook.io/phper/business/4.-ru-he-zuo-jian-kong-tong-ji.md).

# 4.如何做监控统计

自然分钟很简单，不是自然分钟呢？

下面是伪代码：

```php
    function circuitBreaker($count, $limitTime = 60)
    {
        $redisKey = "test_redis";
        $currentTime = time();
        $length = $this->redis->lPush($redisKey, $currentTime);
        // 避免只入不出, 削个峰
        if ($length >= $count) {
            if ($length > $count * 1.5) {
                $this->redis->lTrim($redisKey, 0, $count - 1);
            }
            $previousTime = $this->redis->rPop($redisKey);
            if ($previousTime && ($currentTime - $previousTime <= $limitTime)) {
                return true;
            }
        }
        return false;
    }
```
