note 14593 deleted from function.getmypid by danbrown

From: Date: Sun, 20 Jul 2008 00:28:03 +0000
Subject: note 14593 deleted from function.getmypid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141847@lists.php.net to get a copy of this message
Note Submitter: carl at NOSPAM dot thep dot lu dot se ---- As it is very unlikely today that there will be two PHP processes with the same process ID within the same microsecond, this function can be used for something like srand((int)microtime() ^ getmypid() ^ time()) to have a decent chance of avioding a collision. <p> Just relying on the time in microseconds is a rather Bad Thing to do, since a contect switch might very well take a lot less than that, so there's a decent chance of two simultaneous request to get the same ID. <P> If you're running your php script upon an HTTP request, you might even want to toss in the IP addy of the remote host in your seed for a bit of extra entropy. You can't be too paranoid when it comes to 'random' numbers. <p>(Side note: I tried using hardware to generate random numbers, but with my setup it took just about forever to gather enough entropy. All hail ran3()! )

« previous php.notes (#141847) next »