/** * @return bool */ public function isAlive() { if ($this->process->pid <= 0) { return false; } $startTime = ProcessHelper::getStartTimeByPid($this->process->pid); return (bool) $startTime; }
public function processItinerary() { $id = JRequest::getVar('id', 0, 'post', 'int'); // Check if the user is authorized to do this. if (!JFactory::getUser()->authorise('core.edit.state', $option)) { echo json_encode(array('type' => 'error', 'msg' => JText::_('JERROR_ALERTNOAUTHOR'))); JFactory::getApplication()->close(); } JLoader::register('ProcessHelper', JPATH_COMPONENT . DS . 'helpers' . DS . 'process.php'); $result = ProcessHelper::processItinerary($id); echo json_encode($result); JFactory::getApplication()->close(); }
public function actionIndex($force = false) { $isPMRunning = null; while (true) { if (!$force) { $isPMRunning = ProcessHelper::isPMRunning(); } if (!$isPMRunning) { break; } $cmds = Setting::get('process', null, true); foreach ($cmds as $id => $cmd) { $curTime = time(); $isStillRunning = false; # Getting PID of previous process. if (isset($cmd['pid'])) { $isStillRunning = ProcessHelper::findRunningProcess($cmd['pid']); } # Remove one task kill process from Process Manager List if ($cmd['runOnce'] && !$isStillRunning) { Setting::remove('process.' . $id); } if ($cmd['runOnce']) { echo $cmd['name'] . "\n"; continue; } $isStarted = $cmd['isStarted']; # Running periodic process continously if ((!isset($cmd['lastRun']) || abs($curTime - $cmd['lastRun']) % $cmd['periodCount'] == 0) && !$isStillRunning && $isStarted && !$cmd['runOnce']) { chdir(Yii::getPathOfAlias('application')); exec("process run yiic " . $cmd['command'], $pid); $cmd['lastRun'] = $curTime; $cmd['pid'] = $pid[0]; Setting::set('process.' . $id, $cmd); // Logging // echo "[".date('d-m-Y H:i:s')."] ".$cmd['name']." is running\n"; } } sleep(1); } }
public static function kill($pid) { $output = null; $return = null; chdir(Yii::getPathOfAlias('application')); $process = ProcessHelper::getProcessCommand(); exec($process . ' kill ' . $pid, $output, $return); return $output; }
public function actionSandbox() { echo "Process Sandbox<br/>"; $pid = ProcessHelper::run("Testing Run Once", "yiic test test --name=abcd"); if (!$pid) { echo "Unable to run command, please check Process Manager"; } }