前阵子使用到PHP的posix_getpid,发现在windows下会报错。
所以去查理下文档,把内容整理如下。
posix_getpwuid — Return info about a user by user id(通过用户ID返回关于用户的信息)。
<?php
$userinfo = posix_getpwuid(10000);
print_r($userinfo);
?>
//返回的结果
Array
(
[name] => tom
[passwd] => x
[uid] => 10000
[gid] => 42
[gecos] => "tom,,,"
[dir] => "/home/tom"
[shell] => "/bin/bash"
)
On Windows, posix_getpwuid() is not implemented , but if you just want the username of the current user, you can use get_current_user().
使用这个函数是要注意:在Windows上,posix_getpwuid()没有实现,但是如果你只想要当前用户的用户名,可以使用get_current_user()。