文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php 取得唯一id

php 取得唯一id

时间:2008-04-05  来源:lib


                ?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$n = 100000;
print '1. (microtime): ';
$start = microtime(true);
for ($i=0; $i$n; $i++) {   
    $test = microtime();
}
print (microtime(true) - $start) . "s used \n";
print $test ."\n";
print '2. (microtime): ';
$start = microtime(true);
for ($i=0; $i$n; $i++) {   
    $test = microtime(true);
}
print (microtime(true) - $start) . "s used \n";
print $test ."\n";
print '3. uniqid:  ';
$start = microtime(true);
for ($i=0; $i$n; $i++) {   
    $test =  uniqid('uid', false);
}
print (microtime(true) - $start) . "s used \n";
print $test . "\n\n\n";
速度最快的是第三种
microtime()在php5后才支持传参返回float值,在多核的情况下,第2种方法也许会有重复值 ;在多机器环境下,要给值加不同的前缀区分不同的机器.还是原生php用的好。
               
               

相关阅读 更多 +
排行榜 更多 +
粉末星战 v1.0.0 安卓版

粉末星战 v1.0.0 安卓版

休闲益智 下载
粉末星战 v1.0.0 安卓版

粉末星战 v1.0.0 安卓版

休闲益智 下载
火线反恐部队 v1.2 安卓版

火线反恐部队 v1.2 安卓版

飞行射击 下载