14 namespace HCE\transport {
42 public static function getClientId($type = 1, $prefix = null) {
43 if ($prefix === null) {
44 $prefix = date (
'Y-m-d H:i:s' ) .
'-' . microtime (
true ) .
'-';
47 $ret = PROTOCOL_CLIENT_IDENTITY_PREFIX . $prefix;
51 $ret .= self::getUniqueId ( 1 );
54 $ret .= self::getUniqueId ( 3 ) .
'-' . self::getUniqueId ( 5 );
71 $ret = PROTOCOL_MSG_ID_PREFIX . $prefix;
75 $ret .= self::getUniqueId ( 0 );
78 $ret .= self::getUniqueId ( 4 );
97 $ret = uniqid ( md5 ( rand () ),
true );
98 } elseif ($type == 1) {
100 $ret = dechex ( time () ) . dechex ( mt_rand ( 1, 65535 ) );
101 } elseif ($type == 2) {
103 $r = unpack (
'v*', fread ( fopen (
'/dev/random',
'r' ), 16 ) );
104 $ret = sprintf (
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', $r [1], $r [2], $r [3], $r [4] & 0x0fff | 0x4000, $r [5] & 0x3fff | 0x8000, $r [6], $r [7], $r [8] );
105 } elseif ($type == 3) {
107 $ret = uniqid ( php_uname (
'n' ) .
'-',
true );
108 } elseif ($type == 4) {
110 $ret = time () . substr ( md5 ( microtime (
true ) ), 0, rand ( 5, 12 ) );
111 } elseif ($type == 5) {
113 $ret = sprintf (
'%04x%04x-%04x-%03x4-%04x-%04x%04x%04x', mt_rand ( 0, 65535 ), mt_rand ( 0, 65535 ),
114 mt_rand ( 0, 65535 ),
116 bindec ( substr_replace ( sprintf (
'%016b', mt_rand ( 0, 65535 ) ),
'01', 6, 2 ) ),
120 mt_rand ( 0, 65535 ), mt_rand ( 0, 65535 ), mt_rand ( 0, 65535 ) );