Jump to content

microtime()


felito

Recommended Posts

felito:

  Is it too hard for you to type in www.php.net/microtime?  Maybe you don't realize that the php manual works that way --- you put in the name of the function you want to read about in the url.  microtime 

 

There is a uniquid function.  That function uses microtime to seed a unique id generation algorithm.

 

 

Also... read the responses to your question.  Xyph took the time to reply to you with an example that answered your question about formatting of a time value.  Did you read it? 

 

 

 

If you want an id, then you are going to get something that has the property of uniqueness.  It is going to be a string, not a date/time value.  Do you want a date/time value or a unique string?

 

 

Link to comment
Share on other sites

PHP implements microtime to help create a pseudo-unique value that has a very low chance of being replicated.

 

Using microtime alone generally isn't enough, as it's predictable.

 

And ideal solution would be to use microtime in combination with things like the users IP and very strong pseudo-random (or random if on a *nix system) data.

 

openssl_random_pseudo_bytes is great, but runs very slow on windows systems and isn't always available to use.

 

Using /dev/random on a *nix system ideal, as it uses environment noise for 'true' random generation.

 

As a worst-case fallback, mt_rand with a combination of the IP and microtime is generally enough, but know mt_rand is considered to be insecure cryptographically.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.