Subversion Repositories php_utils

Rev

Rev 27 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 28
Line 20... Line 20...
20
 
20
 
21
function fixed_length_microtime() {
21
function fixed_length_microtime() {
22
        // This function outputs a fixed-length microtime (can be used for sorting)
22
        // This function outputs a fixed-length microtime (can be used for sorting)
23
        // Additionally, it ensures that the output is always different by waiting 1 microsecond
23
        // Additionally, it ensures that the output is always different by waiting 1 microsecond
24
 
24
 
25
        $ary = explode('.', microtime(true));
25
        $ary = explode('.', (string)microtime(true));
26
        if (!isset($ary[1])) $ary[1] = 0;
26
        if (!isset($ary[1])) $ary[1] = 0;
27
        $ret = $ary[0].'_'.str_pad($ary[1], 4, 0, STR_PAD_RIGHT);
27
        $ret = $ary[0].'_'.str_pad($ary[1], 4, '0', STR_PAD_RIGHT);
28
 
28
 
29
        while (true) {
29
        while (true) {
30
                $ary = explode('.', microtime(true));
30
                $ary = explode('.', (string)microtime(true));
31
                if (!isset($ary[1])) $ary[1] = 0;
31
                if (!isset($ary[1])) $ary[1] = 0;
32
                $ret2 = $ary[0].'_'.str_pad($ary[1], 4, 0, STR_PAD_RIGHT);
32
                $ret2 = $ary[0].'_'.str_pad($ary[1], 4, '0', STR_PAD_RIGHT);
33
                // Wait until the value changes. This ensures that the microtime will never be the same
33
                // Wait until the value changes. This ensures that the microtime will never be the same
34
                // sleep(0.1) does not work for some reason.
34
                // sleep(0.1) does not work for some reason.
35
                if ($ret != $ret2) break;
35
                if ($ret != $ret2) break;
36
        }
36
        }
37
 
37