Home > Backend Development > PHP Tutorial > Using uuid in php

Using uuid in php

不言
Release: 2023-03-23 22:38:02
Original
9921 people have browsed it

The content of this article is about the use of uuid in php, which has a certain reference value. Now I share it with you. Friends in need can refer to it


一. Definition

UUID means Universally Unique Identifier, which is a standard for software construction,

The purpose of UUID is to allow all elements in the distributed system to have unique identification information, without the need to specify identification information through a central control terminal. This way, everyone can create UUIDs that don't conflict with anyone else's. In this case, there is no need to consider the duplication of names when creating the database. The most widely used UUID at present is Microsoft's Globally Unique Identifiers (GUIDs), while other important applications include Linux ext2/ext3 file system, LUKS encrypted partition, GNOME, KDE, Mac OS X, etc.
UUID refers to a number generated on one machine, which is guaranteed to be unique to all machines in the same time and space. Usually the platform will provide a generated API. Calculated according to standards set by the Open Software Foundation (OSF), using the Ethernet card address, nanosecond time, chip ID code and many possible numbers
UUID is a combination of the following parts:
(1) Current date and time, the first part of UUID is related to time. If you generate a UUID after a few seconds, the first part is different, and the rest same.
(2) Clock sequence.
(3) Globally unique IEEE machine identification number. If there is a network card, it is obtained from the network card MAC address. If there is no network card, it is obtained by other means.
The only drawback of UUID is that the generated result string will be relatively long. The most commonly used UUID standard is Microsoft's GUID (Globals Unique Identifiers). In ColdFusion, you can use the CreateUUID() function to easily generate a UUID. Its format is: xxxxxxxx-xxxx- xxxx-xxxxxxxxxxxxxxxx (8-4-4-16), where each x is one in the range of 0-9 or a-f. Hexadecimal number.
And The standard UUID format is: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx (8-4-4-4-12), OK Download CreateGUID() UDF from cflib for conversion.


2. Generation method

1. Use the function uuid_create() function or com_create_guid()

Use uuid_create() You need to install the uuid extension before the function. The installation method is as follows

http://www.bubuko.com/infodetail-2390379.html (reprinted)

## 2. Custom function

      


if (!function_exists('com_create_guid')) {
 function com_create_guid() {
  return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
    mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
    mt_rand( 0, 0xffff ),
    mt_rand( 0, 0x0fff ) | 0x4000,
    mt_rand( 0, 0x3fff ) | 0x8000,
    mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
  );
 }
}
Copy after login

Related recommendations:

How to use session in thinkphp

Use hidef instead of define in PHP to optimize efficiency



#

The above is the detailed content of Using uuid in php. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template