Crontab\CrontabFileHandler::write PHP Method

write() public method

Write the current crons in the cron table
public write ( Crontab $crontab ) : CrontabFileHandler
$crontab Crontab
return CrontabFileHandler
    public function write(Crontab $crontab)
    {
        $tmpFile = tempnam(sys_get_temp_dir(), 'cron');
        $this->writeToFile($crontab, $tmpFile);
        $process = new Process($this->crontabCommand($crontab) . ' ' . $tmpFile);
        $process->run();
        $this->error = $process->getErrorOutput();
        $this->output = $process->getOutput();
        return $this;
    }

Usage Example

示例#1
0
 /**
  * Save crons to file
  * 
  * @param string $file /path/to/file/
  */
 public function save()
 {
     $crontabFile = $this->getCrontabFile();
     if (!is_null($crontabFile)) {
         $this->crontabFileHandler->writeToFile($this->crontab, $crontabFile);
     } else {
         $this->crontabFileHandler->write($this->crontab);
     }
     return $this;
 }