將請(qǐng)求存入redis
為了模擬多個(gè)用戶的請(qǐng)求,使用一個(gè)for循環(huán)替代
//redis數(shù)據(jù)入隊(duì)操作
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
for($i=0;$i<50;$i++){
try{
$redis->LPUSH('click',rand(1000,5000));
}catch(Exception $e){
echo $e->getMessage();
}
}
在后臺(tái)進(jìn)行數(shù)據(jù)處理
守護(hù)進(jìn)程
//redis數(shù)據(jù)出隊(duì)操作,從redis中將請(qǐng)求取出
$redis = new Redis();
$redis->pconnect('127.0.0.1',6379);
while(true){
try{
$value = $redis->LPOP('click');
if(!$value){
break;
}
//var_dump($value)."\n";
/*
*? 利用$value進(jìn)行邏輯和數(shù)據(jù)處理
*/
}catch(Exception $e){
echo $e->getMessage();
}
}