Skip to content

Commit 8390674

Browse files
committed
* genLogId新方案
1 parent 60750bb commit 8390674

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

src/HttpServer.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,38 @@ function () use ($controllerInstance, $methodName) {
263263
*/
264264
public function genLogId($request)
265265
{
266+
static $i = 0;
267+
$i || $i = mt_rand(1, 0x7FFFFF);
268+
266269
$logId = $request->header['log_id'] ?? '' ;
267270

268271
if (!$logId) {
269-
$logId = strval(new \MongoId());
272+
$logId = sprintf("%08x%06x%04x%06x",
273+
time() & 0xFFFFFFFF,
274+
crc32(substr((string)gethostname(), 0, 256)) >> 8 & 0xFFFFFF,
275+
getmypid() & 0xFFFF,
276+
$i = $i > 0xFFFFFE ? 1 : $i + 1
277+
);
270278
}
271279

272280
return $logId;
273281
}
282+
283+
284+
function generateIdHex()
285+
{
286+
static $i = 0;
287+
$i OR $i = mt_rand(1, 0x7FFFFF);
288+
289+
return sprintf("%08x%06x%04x%06x",
290+
time() & 0xFFFFFFFF,
291+
292+
crc32(substr((string)gethostname(), 0, 256)) >> 8 & 0xFFFFFF,
293+
294+
getmypid() & 0xFFFF,
295+
296+
$i = $i > 0xFFFFFE ? 1 : $i + 1
297+
);
298+
}
299+
274300
}

src/MSFCli.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,6 @@ function () use ($controllerInstance) {
149149
} while (0);
150150
}
151151

152-
/**
153-
* gen a logId
154-
*
155-
* @param Request $request
156-
* @return string
157-
*/
158-
public function genLogId($request)
159-
{
160-
$logId = strval(new \MongoId());
161-
return $logId;
162-
}
163-
164152
/**
165153
* 服务启动前的初始化
166154
*/

0 commit comments

Comments
 (0)