如果你要使用它以及 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";
?>