php function page

Note: Avoid using this function in multithreaded webservers. It is better to change the file permissions with chmod() after creating the file. Using umask() can lead to unexpected behavior of concurrently running scripts and the webserver itself because they all use the same umask.

My questions are

1) due to the above statement, to make your codes portable for "multithreaded webservers", are you not going to use umask() at all?

2) Will it be possible to totally drop umask, by create and chmod, for example, in the mkdir cases, Could mkdir() and chmod() totally replace umask and mkdir()?

3) will there be any cases that create and chmod cannot replace umask? for example, if you want to get the value of umask, without calling umask(), what else you can do? create a dummy file and check its permission, then calculate the umask (it seems there should be better way to get the umask value without calling php umask() function?

    Umask is used to set default file permissions for a current session, effectively. From http://www.dartmouth.edu/~rc/help/faq/permissions.html:

    Typically the default configuration is equivalent to typing 'umask 22' which produces permissions of:

    -rw-r--r-- for regular files, or
    drwxr-xr-x for directories.

    In other words, user has full access, everyone else (group and other) has read access to files, lookup access to directories.

    The issue with the multithreaded scripts seems to be that if you set a umask on a system that will run the same script from multiple visitors/users, you could get weird results (the result of changing permissions on files that are possibly being used by other processes).

    Mkdir and chmod serve the same purpose as umask - it's simply a convenience factor, as I understand it. By setting a umask, ALL files/directories created after are given that set of permissions. You can do this manually with chmod just as well. You don't need to know the default umask to set permissions on a created file or directory - just set them absolutely with chmod.

      Thanks! in simple words. mkdir + chmod does the same as umask + mkdir + umask back but mkdir + chmod will not have the umask problems on the multithreaded script.

        Write a Reply...