Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate unique id in php based on current data and time?

I need to generate a unique ID in php based on current date and time to keep a log of when i am running code. i.e. every time i run the code it should be able to generate a unique id based on current date and time.

Hope I am clear with my ques. How to do that?

like image 465
user1518659 Avatar asked Aug 28 '12 06:08

user1518659


People also ask

Is PHP time () unique?

This function does not guarantee uniqueness of return value. Since most systems adjust system clock by NTP or like, system time is changed constantly. Therefore, it is possible that this function does not return unique ID for the process/thread.

How are unique ids generated?

Version-1 UUIDs are generated from a time and a node ID (usually the MAC address); version-2 UUIDs are generated from an identifier (usually a group or user ID), time, and a node ID; versions 3 and 5 produce deterministic UUIDs generated by hashing a namespace identifier and name; and version-4 UUIDs are generated ...

What is unique ID in JavaScript?

Introduction to JavaScript UUID. A universally unique identifier (UUID) is an identifier of the 128-bit value that is used in the construction of software. Each bit present in the value differs by the meaning as several variants are considered.


1 Answers

Using time() to create sortable unique id's

Concatenating strings will also further randomize your desired result and still keep it sortable. manual here

$uniqueId= time().'-'.mt_rand();
like image 114
amitchhajer Avatar answered Sep 21 '22 23:09

amitchhajer