不用架构,再烂的PHP代码,再烂的SQL语句,一样能承受5W人同时访问,上一个帖子不知道怎么回事,资源上传后就没了。
这次再发一次。
地址:http://download.csdn.net/detail/q184996833/5800367PHP并发架构SQL
这次再发一次。
地址:http://download.csdn.net/detail/q184996833/5800367PHP并发架构SQL
解决方案 »
- 可以把织梦系统或是帝国cms的采集模块搬得到自己的网站上去?
- 关于json_decode的问题
- wordpress 分类列表显示问题
- 织梦系统 如何做一个多个投票主题 一个提交按钮的投票(如图)
- 如何实现水电缴费接口啊、、
- 大家来看看这个问题关于php.ini设置的
- discuz,phpcms等在common.inc.php做数据库连接是否影响 性能
- thinkphp3.0 中的thinkeditor怎么用
- phpmywind模版开发的网站,上传到空间后好多功能都不能用了,求解
- die(json_encode(... 没返回
- 开发商城系统,遇到的问题
- PHP实现高并发的类,负载平衡,能承受5W人同时访问
class WebSupervene{
private $filename = "";
private $count = 50;
/**
* @return the $filename
*/
public function getFilename() {
return $this->filename;
} /**
* 设置并发访问人数
* @param number $count
*/
public function setCount($count) {
$this->count = $count;
} function __construct(){
$dir="./_runlist";
$this->filename=$dir."/~Supervene";
if(!is_dir($dir)){
mkdir($dir);
}
}
/**
* 缓存队列
*/
private function saveCache($value){
$cache=self::read();
$time = date("YmdHis",time());
$wcache="";
if(!$cache){
$warr[$value]=$time;
$wcache = serialize($warr);
}else{
$warr=unserialize($cache);
$warr_rs=array_keys($warr,$time);
if(empty($warr_rs)){
unset($warr);
$warr[$value]=$time;
$wcache = serialize($warr);
}else{
if(count($warr_rs)<$this->count){
$warr[$value]=$time;
$wcache = serialize($warr);
}else{
return false;
}
}
}
if($wcache!==""){
self::write($wcache);
return true;
}else{
return false;
}
}
/**
* 读取缓存
*/
private function read(){
$fread = fopen(self::getFilename(), "r");
if($fread){
$contents = fread($fread, filesize (self::getFilename()));
fclose($fread);
return $contents;
}else{
return false;
}
}
/**
* 写入缓存
*/
private function write($value){
$fwrite = fopen(self::getFilename(), 'w+');
fwrite($fwrite, $value);
fclose($fwrite);
}
/**
* 主入口
* @param unknown_type $ip
*/
public function Supervene($ip){
if(!self::saveCache($ip)){
echo "<script language=JavaScript> location.replace(location.href);</script>";
exit;
}
}
}
?>