/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/macntr01/suid_suid.inc
ViewVC logotype

Contents of /to_be_filed/webprojs/php_libraries/php_library/macntr01/suid_suid.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (8 years, 2 months ago) by dashley
File size: 3039 byte(s)
Initial commit.
1 <?php
2 //------------------------------------------------------------------------
3 //Marshall Aviation Center FBO Management Software
4 //Copyright (C)2005 David T. Ashley
5 //
6 //This program is free software; you can redistribute it and/or
7 //modify it under the terms of the GNU General Public License
8 //as published by the Free Software Foundation; either version 2
9 //of the License, or (at your option) any later version.
10 //
11 //This program is distributed in the hope that it will be useful,
12 //but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 //GNU General Public License for more details.
15 //
16 //You should have received a copy of the GNU General Public License
17 //along with this program; if not, write to the Free Software
18 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 //
20 //The author (David T. Ashley) may be contacted by e-mail at dta@e3ft.com
21 //and by postal mail at P.O. Box 918, Marshall MI 49068.
22 //------------------------------------------------------------------------
23 //Functions for server-unique identifiers.
24 //
25 //A server-unique identifier is something guaranteed to be unique for the
26 //life of the server. These are the basis for session IDs, etc.
27 //------------------------------------------------------------------------
28 //Gets a unique integer whole time and microtime. The time is
29 //guaranteed unique because this function implements a spinlock
30 //until the time changes.
31 function suid_uniquetime(&$whole_time, &$micro_time)
32 {
33 list($usec_reference, $sec_reference) = explode(" ", microtime());
34 $usec_reference = (int)($usec_reference * 1000000.0);
35
36 $exit_condition = 0;
37
38 while (!$exit_condition)
39 {
40 list($usec, $sec) = explode(" ", microtime());
41 $usec = (int)($usec * 1000000.0);
42
43 if (($usec == $usec_reference) && ($sec == $sec_reference))
44 {
45 //The time has not changed. Use usleep() to try to
46 //give a time breather without chewing CPU time.
47 usleep(100);
48 }
49 else
50 {
51 //The time has changed. We can leave the loop.
52 $exit_condition = 1;
53 }
54 }
55
56 //Assign the values for the caller.
57 $whole_time = $sec_reference;
58 $micro_time = $usec_reference;
59 }
60
61 //------------------------------------------------------------------------
62 //Returns a SUID as documented. Format will be:
63 // PID -- 8 hexadecimal digits.
64 // WHOLE TIME -- 10 hexadecimal digits.
65 // NANO TIME -- 8 hexadecimal digits.
66 //
67 function suid_suid()
68 {
69 $pidstring = sprintf("0000%04X", getmypid());
70
71 suid_uniquetime($secs_out, $usecs_out);
72
73 $wholestring = sprintf("%010X", $secs_out);
74
75 $usecs_out = $usecs_out * 1000;
76 $fracstring = sprintf("%08X", $usecs_out);
77
78 return($pidstring . $wholestring . $fracstring);
79 }
80
81 //------------------------------------------------------------------------
82 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25