設想一個呼叫中心不能被客戶每分鐘超過2次呼叫淹沒。因此,該範圍之外的任何人都將獲得電子郵件支持鏈接($ bTrigger = FALSE)。其他人($ bTrigger = TRUE)將獲得技術支持電話號碼。每分鐘間隔觸發x個動作的最有效方法是什麼?
腳本是PHP。那麼,建立這個最有效率和最準確的方法是什麼?
這是我到目前爲止,但不幸的是它只是每分鐘觸發一次。我似乎無法弄清楚爲什麼它不會每分鐘運行兩次。
<?php
$bTrigger = FALSE;
$sDir = dirname(__FILE__);
$sDir = rtrim($sDir,'/');
$sFile = $sDir . '/MINUTE-TIMER.txt';
$sLine = @ file_get_contents($sFile);
$sLine = str_replace("\r\n",'',$sLine);
$sLine = str_replace("\r",'',$sLine);
$sLine = str_replace("\n",'',$sLine);
$sLine = str_replace("\t",'',$sLine);
$asParts = explode(',',$sLine);
$nLetThru = @ $asParts[0];
$nLetThru = intval($nLetThru);
$nLastMin = @ $asParts[1];
$nLastMin = intval($nLastMin);
$nCurMin = intval(date('i'));
if (empty($sLine)) {
$nLetThru = 0;
$nLastMin = 0;
}
$nMaxLetThru = 2;
if ($nCurMin != $nLastMin) { // meaning, a new minute since last checked
if ($nLetThru <= $nMaxLetThru) { // meaning, we haven't hit more than max allowed
$bTrigger = TRUE;
++$nLetThru;
file_put_contents($sFile,"$nLetThru,$nCurMin");
} else {
file_put_contents($sFile,"0,$nCurMin");
}
}
if ($bTrigger) {
echo 'TRIGGERED!!!!';
} else {
echo 'not triggered';
}
我們在這裏幫助您解決特定問題,而不是爲您做好工作。 –
@MarcB我即將回答它,然後人們可以挑戰這個答案。我將從挑戰中學習。 – Volomike
您的問題需要改進。如果你有答案,爲什麼不包括它? – Kermit