将请求存入redis
为了模拟多个用户的请求,使用一个for循环替代
//redis数据入队操作$redis = new Redis();$redis->connect('127.0.0.1',6379);for($i=0;$i<50;$i++){try{$redis->lPush('test',rand(1000,9000));
}catch(Exception $e){echo $e->getMessage();
}
}#####################################################
在后台进行数据处理
守护进程
//redis数据出队操作,从redis中将请求取出$redis = new Redis();$redis->pconnect('127.0.0.1',6379);while(true){try{$value = $redis->lPop('test');if(!$value){break;
}//var_dump($value)."n";/* * 对$value进行逻辑和数据处理 */}catch(Exception $e){echo $e->getMessage();
}
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号