Piwik\Filesystem::checkIfFileSystemIsNFS PHP Method

checkIfFileSystemIsNFS() public static method

Note: In order to figure this out, we try to run the 'df' program. If the 'exec' or 'shell_exec' functions are not available, we can't do the check.
public static checkIfFileSystemIsNFS ( ) : boolean
return boolean True if on an NFS filesystem, false if otherwise or if we can't use shell_exec or exec.
    public static function checkIfFileSystemIsNFS()
    {
        $sessionsPath = Session::getSessionsDirectory();
        // this command will display details for the filesystem that holds the $sessionsPath
        // path, but only if its type is NFS. if not NFS, df will return one or less lines
        // and the return code 1. if NFS, it will return 0 and at least 2 lines of text.
        $command = "df -T -t nfs \"{$sessionsPath}\" 2>&1";
        if (function_exists('exec')) {
            // use exec
            $output = $returnCode = null;
            @exec($command, $output, $returnCode);
            // check if filesystem is NFS
            if ($returnCode == 0 && count($output) > 1) {
                return true;
            }
        } elseif (function_exists('shell_exec')) {
            // use shell_exec
            $output = @shell_exec($command);
            if ($output) {
                $commandFailed = false !== strpos($output, "no file systems processed");
                $output = explode("\n", trim($output));
                if (!$commandFailed && count($output) > 1) {
                    // check if filesystem is NFS
                    return true;
                }
            }
        }
        return false;
        // not NFS, or we can't run a program to find out
    }

Usage Example

Example #1
0
 public function execute()
 {
     $label = $this->translator->translate('Installation_Filesystem');
     if (!Filesystem::checkIfFileSystemIsNFS()) {
         return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK));
     }
     $isPiwikInstalling = !Config::getInstance()->existsLocalConfig();
     if ($isPiwikInstalling) {
         $help = 'Installation_NfsFilesystemWarningSuffixInstall';
     } else {
         $help = 'Installation_NfsFilesystemWarningSuffixAdmin';
     }
     $comment = sprintf('%s<br />%s', $this->translator->translate('Installation_NfsFilesystemWarning'), $this->translator->translate($help));
     return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
 }
All Usage Examples Of Piwik\Filesystem::checkIfFileSystemIsNFS