如果您要将此与 posix_setuid 一起使用,请确保先调用 posix_setgid
<?php
define (PROC_USER, 'john');
define (PROC_GRP, 'admins');
?>
以下有效
<?php
$user = posix_getpwnam( PROC_USER );
$group = posix_getgrnam( PROC_GRP);
echo posix_getuid()."\n";
echo posix_getgid()."\n";
posix_setgid($group['gid']);
posix_setuid($user['uid']);
echo posix_getuid()."\n";
echo posix_getgid()."\n";
?>
以下不会设置 gid
<?php
$user = posix_getpwnam( PROC_USER );
$group = posix_getgrnam( PROC_GRP);
echo posix_getuid()."\n";
echo posix_getgid()."\n";
posix_setuid($user['uid']);
posix_setgid($group['gid']);
echo posix_getuid()."\n";
echo posix_getgid()."\n";
?>