note 32440 added to function.uniqid

From: Date: Tue, 27 May 2003 22:06:13 +0000
Subject: note 32440 added to function.uniqid
Groups: php.notes 
Request: Send a blank email to php-notes+get-49117@lists.php.net to get a copy of this message
Here is a way to generate a uniqid on a Unix network. Your system must support hostid command. <? # Get the hostid of the machine. This should be unique on # your network. Usually hostid is a hexadecimal number, so # we use hexdec() function to convert it to a decimal one: $hostid = hexdec(shell_exec("hostid")); # Get time of the day in seconds and microseconds: $td = gettimeofday(); # Use combination of seconds, microseconds, pid and hostid # to generate a unique number. # This way even if one or 2 systems execute this command # on a very fast machine, at exactly the same time(even # same within microseconds), with the same pid number # (which is very unlikely), you'll still have a unique # number because of your hostid even on a very large # network with very fast servers: echo $td["sec"].$td["usec"]. getmypid(). $hostid; ?> Of course you can use md5() to generate a 32 byte character string of the above output: echo md5($td["sec"].$td["usec"]. getmypid(). $hostid); ---- Manual Page -- http://www.php.net/manual/en/function.uniqid.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32440 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32440&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32440&report=yes

« previous php.notes (#49117) next »