単一の MySQL クエリでこれを行う方法:
if (select count(*)..)=10
select a record from the same table
else
insert a record into the same table
単一の MySQL クエリでこれを行う方法:
if (select count(*)..)=10
select a record from the same table
else
insert a record into the same table
関係する Web サーバーが 1 つだけである限り、APC http://php.net/manual/de/book.apc.phpをタイムアウトの優れたシステムで試してみます。
例: IP が過去 2 秒間に既に要求を送信している場合、現在の要求は拒否され、タイムアウトは 4 秒に変更され、その後 10 秒などに変更されます。
if ($timeoutLevel = apc_fetch("locked_" . $ip)){
$timeoutLevel++;
$timeout = getNextTimeout($timeoutLevel);
apc_store("locked_".$ip, $timeoutLevel, $timeout);
show_my_error_page(get_friendly_text("please do not try again for $timeout seconds! You are Blocked!"));
exit();
}
else{
$timeoutLevel = 1;
$timeout = INITIAL_PAGE_TIMEOUT;
apc_store("locked_".$ip, $timeoutLevel, $timeout);
}
これは、最後の x 秒の ip あたり最大で約 50 バイトのコストがかかるため、DDOS でない場合、Web サーバーにはその RAM が必要です。
ただし、注意してください: 一部の html ページには、css、javascript、画像、サウンド、ajax 呼び出しが後で来る可能性、json リクエストなどへの参照が含まれています。
$timeout 秒後、APC は自動的に値を下げるので、掃除婦を雇う必要はありません。