note 14593 added to function.getmypid.php

From: Date: Sun, 05 Aug 2001 20:07:04 +0000
Subject: note 14593 added to function.getmypid.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-16351@lists.php.net to get a copy of this message
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()! ) http://www.php.net/manual/en/function.getmypid.php

« previous php.notes (#16351) next »