RE: [PHP] gettimeofday() question

From: Date: Wed, 14 Feb 2001 21:08:29 +0000
Subject: RE: [PHP] gettimeofday() question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39740@lists.php.net to get a copy of this message
> I need to be able to create files with unique names. One thought > I had was > to use the date functions. In windows API you can call a function that > returns the number of milliseconds since, I think its January 1, > 1970. That > number would pretty much be garunteed to be unuquie (although it could be > long, noone has to read these names). > > if I use the PHP gettimeofday() function and get the "usec" value, would > this be the same thing? The manual is unclear about what the usecs is in > reference to. Up until PHP 4.0.5 gettimeofday under windows is unreliable as a timing mechanism although this has now been fixed. Before PHP 4.0.5 PHP does return some sort of contrived usec value for the time, after PHP 4.0.5 it will return a value accurate to the nearest millisecond rather than microsecond. This should not really affect the randomness of the function that much and the interface from the PHP end is identical (usec value will be milliseconds not microseconds). I would suggest using somthing like srand((double)microtime()*1000000); $unique_id = md5(rand(0,32000)); which is very effective for creating unique id's. James

« previous php.general (#39740) next »