$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '123456';
$db_name = 'test';
$link = mysql_pconnect($db_host, $db_user, $db_pwd) or
die('连接失败');
mysql_select_db($db_name, $link);
function random($length,$string =
'0123456789abcdefghijklmnopqrstuvwxyz') {
$rstr = '';
$strlen = strlen($string);
for ($i=0; $i
$rstr .=
$string{mt_rand(0,$strlen-1)};
}
return $rstr;
}
function getmtime() {
$time = explode(' ', microtime());
return $time[0]+$time[1];
}
if ( $_GET['ac'] == 'make' ) {
$stime = intval($_GET['stime']);
$total = intval($_GET['total']);
$num = intval($_GET['num']);
$limit = intval($_GET['limit']);
$starttime = getmtime();
if ( empty($stime) ) {
$stime = $starttime;
}
!$total && $total =
intval($_POST['total']);
!$num && $num =
intval($_POST['num']);
!$limit && $limit =
intval($_POST['limit']);
$sql = "INSERT INTO pub_code (code) VALUES ";
$sp = '';
for ( $i = 1; $i <= $num; $i++ ) {
$sql .=
$sp.'(''.random(9).'')';
$sp = ', ';
}
mysql_unbuffered_query($sql, $link);
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM
pub_code"), 0);
if ( $count >= $total ) {
$endtime = getmtime();
exit('任务完成,共生成'.$count.'个,耗时:'.number_format($endtime
- $stime, 6).'秒');
} else {
$endtime = getmtime();
$url =
"random.php?ac=make&stime={$stime}&total={$total}&num={$num}&limit={$limit}";
$percent = ceil($count/$total
* 100);
$barlen = $percent * 6;
$ctime =
number_format($endtime - $starttime, 3);
$ovtime =
ceil((($total-$count)/$num)*$ctime + (($total-$count)/$num) *
($limit/1000));
echo
'
共生成'.$total.'个,已完成'.$count.'个,本次耗时
'.$ctime.' 秒,预计剩余时间
'.floor($ovtime/3600).'小时'.floor(($ovtime600)/60).'分'.($ovtime`).'秒
:
style="height:23px;line-height:23px;width:600px;border:1px solid
#FAA547;font-family:Verdana;color:#fff">
style="background:#FAA547;width:'.$barlen.'px">'.$percent.'%
}
} else {
?>
随机数生成器cellpadding="5" cellspacing="1"
bgcolor="#CCCCCC">
bgcolor="#f0f0f0">随机数生成器
action="random.php?ac=make" target="make">
每次生成
size="10" /> 个,共生成
name="total" value="100000" size="10" /> 个,时间间隔
size="10" /> 毫秒,
value=" 开 始 " style="padding:3px" />
frameborder="0">
}
?>