自动跑code,往数据库里存好多唯一code

public function run(){
		
	$t = (int)time();	
	$stop = $t + 5;

	for ($i = 1; ; $i++) {
		if ((int)time() > $stop) {
			break;
		}
		
		$id = $this->index();
		if($i == 1 ){
			$first = $id;
		}
	}
		
	echo "<h1>";
	echo $first;
	echo "<br>";
	echo $id;
	echo "</h1>";
	echo "5秒钟跑了".(int)$id-(int)$first; */
}
    
public function index(){
		
	$code = $this->create_code();
		
	$data['code'] = $code;
	$data['codeurl'] = "http://".$code.".ma.lang100.com/";
	$url = "http://".$code.".ma.lang100.com/";

	$codecode = M('ma')->data(array('code'=>$code,'url'=>$url))->add();
		
	return $codecode; 
}
	
	
	
private function create_code($namespace = '') {
	static $guid = '';
	$uid = uniqid("", true);
	$data = $namespace;
	$data .= $_SERVER['REQUEST_TIME'];
	$data .= $_SERVER['HTTP_USER_AGENT'];
	$data .= $_SERVER['LOCAL_ADDR'];
	$data .= $_SERVER['LOCAL_PORT'];
	$data .= $_SERVER['REMOTE_ADDR'];
	$data .= $_SERVER['REMOTE_PORT'];
	$hash = strtolower(hash('ripemd128', $uid . $guid . md5($data)));
	$guid = substr($hash, 0, 8).substr($hash, 8, 4).substr($hash, 12, 4).substr($hash, 16, 4).substr($hash, 20, 12);
	return $guid;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值