Home > Backend Development > PHP Tutorial > PHP高并发的类

PHP高并发的类

WBOY
Release: 2016-06-23 14:16:41
Original
46648 people have browsed it

PHP 并发 架构 SQL

不用架构,再烂的PHP代码,再烂的SQL语句,一样能承受5W人同时访问,上一个帖子不知道怎么回事,资源上传后就没了。
这次再发一次。
地址: http://download.csdn.net/detail/q184996833/5800367

回复讨论(解决方案)



坐等斑竹评论

坐等楼主给分

请lz支援资源分

你们自己评价一下,值不值得化 5 分

<?phpclass 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;		}	}}?>
Copy after login

收藏,以后学学

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template