phpwindowschgrp

What are file groups (changed using chgrp()) in PHP?


I searched for this information on Google but couldn't find anything detailed. I was reading about the chgrp() and it mentioned that this function can change file group.

There is no explanation about what a file group is. I also tried to run the example on reference page to see if the output could help me understand more about the function but the output seemed to be just the number zero. Here is the example code:

$filename = 'stats.txt';
$format = "%s's Group ID @ : %d\n";
printf($format, $filename, filegroup($filename));
chgrp($filename, 10);
clearstatcache(); // do not cache filegroup() results
printf($format, $filename, filegroup($filename));

Here is the output of that code:

stats.txt's Group ID : 0
stats.txt's Group ID : 0

Solution

  • In unix, file ownership is based on an owner and a group.

    Here's a directory listing on a linux box:

    [vagrant@localhost:nginx]$ ls -l
    total 8
    drwxrwxrwx. 1 vagrant vagrant  136 Feb  5  2016 configs
    -rwxrwxrwx. 1 vagrant vagrant 1348 Aug 19 07:34 docker-entrypoint.sh
    -rwxrwxrwx. 1 vagrant vagrant  786 Feb  5  2016 Dockerfile
    

    In this case, the file docker-entrypoint.sh is owned by a user named "vagrant" and a group named "vagrant".

    Permissions are then assigned to one of 3 separate groups:

    You are focused on the chgrp() function which is simply a wrapper around the linux chgrp api/command.

    The groups on a linux box can be examined with

    cat /etc/group

    The number at the end of each entry is the group number. You can typically manipulate group membership using a group name or number, so in your example, you are displaying a group number apparently, but there is some group name associated with that group.

    [vagrant@localhost:nginx]$ cat /etc/group
    root:x:0:
    bin:x:1:
    daemon:x:2:
    sys:x:3:
    adm:x:4:
    tty:x:5:
    disk:x:6:
    lp:x:7:
    mem:x:8:
    

    There are similarities and differences between windows and unix/mac systems but they aren't 100% equivalent. Here's a good article on this topic.