简体   繁体   English

PHP:在Docker容器内获取唯一ID

[英]PHP: Get unique ID inside Docker container

To register with a MQTT service I need a unique client ID inside a Docker container. 要注册MQTT服务,我需要在Docker容器内有一个唯一的客户端ID。 Does the PHP function uniqid() work for that? PHP函数uniqid()是否为此工作?

$uniqueId = uniqid();

Or is it better to combine this with the Docker container ID? 还是将其与Docker容器ID结合起来更好? What is PHP oneliner code for that? PHP oneliner的代码是什么?

 uniqid ([ string $prefix = "" [, bool $more_entropy = FALSE ]] ) : string

Gets a prefixed unique identifier based on the current time in microseconds. 根据当前时间(以微秒为单位)获取带前缀的唯一标识符。

Caution 警告

This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. 此函数不会生成加密安全值,并且不应将其用于加密目的。 If you need a cryptographically secure value, consider using random_int(), random_bytes(), or openssl_random_pseudo_bytes() instead. 如果需要密码安全的值,请考虑改用random_int(),random_bytes()或openssl_random_pseudo_bytes()。

If you are using 如果您正在使用

$id = uniqid (null, true);

You should be totally fine. 你应该没事的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM