唯一key的生成规则,可自己视情况改动

<?php

function getMillisecond()
{
    $time = explode ( " ", microtime ());
    $time = $time[1] . ($time[0] * 1000);
    $time2 = explode( ".", $time );
    $time = $time2[0];
    return $time;
}


function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+_=-/#';
    $charactersLength = strlen($characters);
    $randomString = '';

    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }

    return $randomString;
}

var_dump(gethostname());
var_dump(getmypid());
var_dump(getMillisecond());
var_dump(generateRandomString());

$uniqueStr = uniqid(gethostname() . getmypid() . getMillisecond() . generateRandomString(), true);
$str = hash('md5', $uniqueStr);
var_dump($str);

  

posted @ 2017-11-14 17:03  spectrelb  阅读(474)  评论(0编辑  收藏  举报