Example #1
0
 /**
  * 文件系统IP统计测试
  */
 public function testStatistics()
 {
     // 设置文件存储类配置
     $file_config = array('interval' => 60, 'mode' => 'redis', 'type' => 'time', 'host' => '127.0.0.1', 'port' => 6379, 'auth' => '');
     // 获取一个实例对象
     $ipWatcher = Shuiguang\IpWatch::getInstance($file_config);
     // 允许单个IP在$interval秒内最大访问次数
     $max_request = 10;
     // 获取当前IP访问次数
     $current = $ipWatcher->get();
     // 超过这个次数则退出脚本, 打印出请求次数
     if ($current >= $max_request) {
         echo 'Too many connections';
     }
     $current = $ipWatcher->incr();
     // 打印出当前IP访问的次数
     echo $ipWatcher->get_client_ip() . ':' . $current . "\n";
 }
Example #2
0
 /**
  * 文件系统IP统计测试
  */
 public function testStatistics()
 {
     // 设置文件存储类配置
     $file_config = array('interval' => 60, 'mode' => 'file', 'type' => 'time', 'file_dir' => sys_get_temp_dir() . '/time', 'prefix' => '', 'suffix' => '.time');
     // 获取一个实例对象
     $ipWatcher = Shuiguang\IpWatch::getInstance($file_config);
     // 允许单个IP在$interval秒内最大访问次数
     $max_request = 10;
     // 获取当前IP访问次数
     $current = $ipWatcher->get();
     // 超过这个次数则退出脚本, 打印出请求次数
     if ($current >= $max_request) {
         echo 'Too many connections';
     }
     $current = $ipWatcher->incr();
     // 打印出当前IP访问的次数
     echo $ipWatcher->get_client_ip() . ':' . $current . "\n";
 }