2011-04-28 9 views
1

PHP Captchaでワニスキャッシュが動作していますが、
がわかりません。アンチサイト廃棄アルゴリズムのPHP Captchaでのワニスキャッシュ

1時間(または分)ごとに非常に多くのリクエストが制限された後に、
のキャプチャ入力が送信されます。

私はそれを動作させていますが、req/sの制限をどのように変更できるかを理解したいと思います。このコードは私に何を言っている
http://drcarter.info/2010/04/how-fighting-against-scraping-using-varnish-vcl-inline-c-memcached/

:ここ

はからのコードですか?

if (rc == MEMCACHED_SUCCESS) { 
uint64_t intval; 
rc= memcached_increment(memc, key, strlen(key), (uint64_t)1, &intval); 

if (rc != MEMCACHED_SUCCESS) 
    rc= memcached_set(memc, key, strlen(key), "1", 1, (time_t)60, (uint32_t)0); 
else 
    if (intval>30) { 
    VRT_SetHdr(sp, HDR_REQ, "\013X-Scraping:", "1", vrt_magic_string_end); 
    syslog(LOG_INFO, "Scraping detected from %s",VRT_IP_string(sp, VRT_r_client_ip(sp))); 
    if (intval<300) 
     rc= memcached_set(memc, key, strlen(key), "500", 3, (time_t)3600, (uint32_t)0); 
    } 

ご忠告いただきますようお願い申し上げます。

ありがとうございます!

答えて

0

コードは、このフローで動作します:

try to increment the key identifying the client and return the value in intval 
if it fails set the key with an expiration of 60 seconds 
else 
    if the number of call (intval) is less than 30 
    it set an header X-Scraping (which will be use later to deny access: this part is not in the part of the code you have pasted) 

あなたはRES /秒を変更したい場合ので、あなたは60

1
よりもどちらか> 30テストまたは何か他のものへのキーの有効期限を変更することで再生することができます

私のコードにコメントしていないと私は失礼です:)

だから私はあなたが理解すると思います。

if (rc == MEMCACHED_SUCCESS) { 
//if connected to memcache 
uint64_t intval; 
//trying to increment the "ip address" key (+1) 
rc= memcached_increment(memc, key, strlen(key), (uint64_t)1, &intval); 

if (rc != MEMCACHED_SUCCESS) 
    //if increment fail, then it is the first time that we see this address 
    //init the value at 1 for 60 seconds 
    rc= memcached_set(memc, key, strlen(key), "1", 1, (time_t)60, (uint32_t)0); 
else 
    //if increment success, then verifying the value, if more than 30 (30 reqs/minute) 
    //blacklist the ipaddress (setting the value arbitrary at 500 for 1 hour) 
    if (intval>30) { 
    VRT_SetHdr(sp, HDR_REQ, "\013X-Scraping:", "1", vrt_magic_string_end); 
    syslog(LOG_INFO, "Scraping detected from %s",VRT_IP_string(sp, VRT_r_client_ip(sp))); 
    if (intval<300) 
     rc= memcached_set(memc, key, strlen(key), "500", 3, (time_t)3600, (uint32_t)0); 
    }