Home > Article > Backend Development > Using uuid in php
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
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.
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)
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 ) ); } }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!