Home > php教程 > php手册 > body text

PHP中生成UUID,PHP生成UUID

WBOY
Release: 2016-06-13 09:24:17
Original
1585 people have browsed it

PHP中生成UUID,PHP生成UUID

一、什么是UUID

  简单的说UUID就是一串全球唯一的(16进制)数字串。

  UUID的全拼为“Universally Unique Identifier”,可以译为“通用唯一识别码”。UUID由开源软件基金会 (Open Software Foundation, OSF) 定义,是分布式计算环境 (Distributed Computing Environment, DCE) 的一个组成部分。

  UUID的标准格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx”,五个部分分别为8个字符、4个字符、4个字符、4个字符、12个字符,中间用“-”号间隔。常见的GUID(Globally Unique Identifier)是微软对UUID标准的一种实现。

 

二、为什么要使用UUID

  好处那叫一个多呀~~~,您随便百度把。

三、UUID的生成代码

  这个……,真心过时了,用扩展吧,别自己写代码了。

四、安装UUID扩展

  相关的扩展在这里:PECL :: Package :: uuid。

  PHP扩展安装步骤一直就是那几个:

  

<span>wget</span> http:<span>//</span><span>pecl.php.net/get/uuid-1.0.3.tgz</span>
<span>tar</span> zxvf uuid-<span>1.0</span>.<span>3</span><span>.tgz
cd uuid</span>-<span>1.0</span>.<span>3</span><span>
phpize
.</span>/<span>configure
</span><span>make</span>
<span>make</span> <span>install</span>
Copy after login

  好了,然后编辑一下PHP配置文件,重启一下服务器,到phpinfo()去看效果吧:

  安装成功之后,写两行代码测试一下吧:

  

<span>1</span> <?<span>php
</span><span>2</span> <span>//</span><span>uuid.php</span>
<span>3</span> <span>echo</span> uuid_create(), '<br />\n'<span>;
</span><span>4</span> <span>echo</span> uuid_create(1);    <span>//</span><span>建议用法</span>
Copy after login

  刷新几次页面,观察一下两行UUID的变化,有什么发现吗?想进一步了解的话,请学习一下UUID的几个版本是如何定义的吧。

五、安装扩展可能遇到的问题

  安装扩展遇到问题一般都是系统缺少相关组件造成的。

  在centos 7中,需要先安装libuuid-devel,这个用yum命令就可以了。

  在mac os 10.9中则需要先安装libuuid,这个要到libuuid | SourceForge.net下载。

 

好了,就这些,有真正的v1 UUID可用了。

linux已经安装了php扩展uuid 但是还报Call to undefined function uuid_make()这个错误,为甚


是否已经有MYSQL
否则
PHP.INI配置有问题
 

js中怎产生uuid

www.broofa.com/Tools/Math.uuid.js

Math.uuid = (function() {

// Private array of chars to use

var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');

return function (len, radix) {

var chars = CHARS, uuid = [], rnd = Math.random;

radix = radix || chars.length;

if (len) {

// Compact form

for (var i = 0; i
} else {

// rfc4122, version 4 form

var r;

// rfc4122 requires these characters

uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';

uuid[14] = '4';

// Fill in random data. At i==19 set the high bits of clock sequence as

// per rfc4122, sec. 4.1.5

for (var i = 0; i
if (!uuid[i]) {

r = 0 | rnd()*16;

uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];

}

}

}

return uuid.join('');

};

})();

// Deprecated - only here for backward compatability

var randomUUID = Math.uuid;

function generateUUID()

{

return Math.uuid();

}...余下全文>>
 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!