note 32440 deleted from function.uniqid by bjori

From: Date: Tue, 11 Apr 2006 20:57:48 +0000
Subject: note 32440 deleted from function.uniqid by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-107806@lists.php.net to get a copy of this message
Note Submitter: Habib Valanejad ---- 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);

« previous php.notes (#107806) next »