Database->insert('Task', array('User' => $this->System->Modules['User']->User['Id'], 'Title' => $Title, 'TimeCreate' => 'NOW()', 'CommandList' => $CommandList)); } function ProcessAll() { chdir($this->Config['BaseDir']); $DbResult = $this->Database->query('SELECT * FROM Task WHERE State = 0 ORDER BY Id,TimeCreate ASC'); while($Task = $DbResult->fetch_assoc()) { $this->Database->query('UPDATE Task SET TimeStart=NOW(), State=1 WHERE Id='.$Task['Id']); echo('Provádím úlohu '.$Task['Id'].': '.$Task['Title']."...\n"); $Task['CommandList'] = "#!/bin/sh\n".str_replace("\r", '', $Task['CommandList']); file_put_contents($this->TempScript, $Task['CommandList']); chmod($this->TempScript, 0755); exec($this->TempScript.' >'.$this->TempScript.'.log 2>'.$this->TempScript.'.err'); $StdOut = file_get_contents($this->TempScript.'.log'); unlink($this->TempScript.'.log'); $StdErr = file_get_contents($this->TempScript.'.err'); unlink($this->TempScript.'.err'); echo("Hotovo\n"); $this->Database->query('UPDATE `Task` SET `TimeEnd`=NOW(), `State`=2, `Output`="'.addslashes($StdOut).'", `Error`="'.addslashes($StdErr).'" WHERE `Id`='.$Task['Id']); } } function ProcessAllCycle() { $this->Database->query('UPDATE Task SET State=2 WHERE State=1'); // Change not finished running tasks to finished $this->Database->query('UPDATE Task SET TimeEnd=NOW() WHERE State=2 AND TimeEnd = NULL'); // Set end time to finished tasks while(1) { $this->ProcessAll(); sleep(1); } } function Abort($Id) { $this->Database->query('DELETE FROM Task WHERE Id='.$Id); } }