Michael Robinton wrote:
>>>I'm just curious - what's wrong with the function you're already using?
>>
>>Mod_Perl hangs on to it's PID, so it's no longer unique. (I _believe_)
>
>
>> TIMESTAMP . $$ . $GLOBAL++
Do not use concat, but sprintf 0 padding. Here is an example that can
happen easily which produces two identical ids in two different procs:
P TIMESTAMP $$ $GLOB CONCAT SPRINTF
A 1020227781 753 3 10202277817533 1020227781007533
B 1020227781 75 33 10202277817533 10202277810007533
As you can see if you don't pad $$ with 0 to the max proc's len (on some
machines 63999) you can get two identical UUIDs in CONCAT column above.
The same can happen with the edge of timestamp when its first digit
switches from 9 -> 10, but then this number is so big, this is most
likely won't be a problem.
So a much safer solution would be :
$uuid = time . sprintf("%05", $$) . $GLOBAL++;
s/05/06/ or other if your system's process ID can be bigger than 5 digits.
if you don't modify $^T and you don't reuse the timestamp set for you in
$r, this will save you a few more millisecs:
$uuid = $^T . sprintf("%05", $$) . $GLOBAL++;
Since $^T . sprintf("%05", $$) is unique across processes. It's not
possible to create two processes with the same $$, at the same time.
$^T is the time the Perl interpreter has been started, unless it was
modified later.
You can also move all this "work" in the ChildCleanup Handler, so during
the request time, you use a value that has been already precalculated
for the current request at the end of the previous one. (just make sure
to initialize it during the ChildInit Handler for the first request).
p.s. this concept works on Unix for sure, it's possible that on some OSs
it won't work.
p.p.s. in mod_perl 2.0 we have APR::UUID that does this work for you.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com