Jobby\Helper::getSystemNullDevice PHP Method

getSystemNullDevice() public method

public getSystemNullDevice ( )
    public function getSystemNullDevice()
    {
        $platform = $this->getPlatform();
        if ($platform === self::UNIX) {
            return "/dev/null";
        }
        return "NUL";
    }

Usage Example

Beispiel #1
0
 protected function runFile()
 {
     // If job should run as another user, we must be on *nix and
     // must have sudo privileges.
     $isUnix = $this->helper->getPlatform() === Helper::UNIX;
     $useSudo = '';
     if ($isUnix) {
         $runAs = $this->config['runAs'];
         $isRoot = posix_getuid() === 0;
         if (!empty($runAs) && $isRoot) {
             $useSudo = "sudo -u {$runAs}";
         }
     }
     // Start execution. Run in foreground (will block).
     $command = $this->config['command'];
     $logfile = $this->getLogfile() ?: $this->helper->getSystemNullDevice();
     exec("{$useSudo} {$command} 1>> \"{$logfile}\" 2>&1", $dummy, $retval);
     if ($retval !== 0) {
         throw new Exception("Job exited with status '{$retval}'.");
     }
 }