用于过滤快速重复的请求
程序员文章站
2024-01-16 00:00:58
...
无详细内容 无 ?phpfunction C($key){ $c_arr = array( 'DDOS_MEMCACHE_PERSISTENT_ID_COUNT' = 200, 'DDOS_MEMCACHE_HOST' = '127.0.0.1', // 需要重启apache生效 'DDOS_MEMCACHE_PORT' = 11211, // 需要重启apache生效 'DDOS_MEMCACHE_EXPIRE' = 2, ); retu
200, 'DDOS_MEMCACHE_HOST' => '127.0.0.1', // 需要重启apache生效 'DDOS_MEMCACHE_PORT' => 11211, // 需要重启apache生效 'DDOS_MEMCACHE_EXPIRE' => 2, ); return $c_arr[$key]; } /** * @brief isDdos 判断是否为过快速的ddos攻击 * * @param $index_arr * * @return */ function isDdos($index_arr){ $persistent_id = mt_rand(1, C('DDOS_MEMCACHE_PERSISTENT_ID_COUNT')); $m = new Memcached($persistent_id); if(!$m->getServerList()) { $m->addServer(C('DDOS_MEMCACHE_HOST'), C('DDOS_MEMCACHE_PORT')); } $key = md5(http_build_query($index_arr)); $ret = $m->get($key) === 1 ? true : false; $m->set($key, 1, C('DDOS_MEMCACHE_EXPIRE')); return $ret; } if(isDdos(array('tjx', 'fdf'))){ echo 'ddos'; die(); } sleep(2); echo 'return value';