protected function checkStatus() { $mainNode = $this->template->getElementById('siteContent'); if (!array_key_exists('process', $_SESSION['BackgroundProcess'][$this->process]) || !$_SESSION['BackgroundProcess'][$this->process]['process']) { $this->template->setDisplayDataImmediate('background_status', 'Do not know the OS process number associated to this process', $mainNode); return false; } $this->template->setDisplayDataImmediate('process_number', $this->process, $mainNode); $this->template->setDisplayDataImmediate('background_tail', '', $mainNode); if (!I2CE_FileSearch::isUnixy()) { return true; } $process = $_SESSION['BackgroundProcess'][$this->process]['process']; exec("ps -Ho pid,ppid,pcpu,stime,start_time,size,vsize,comm -p {$process} --ppid {$process}", $output); if (count($output) > 1) { for ($i = 0; $i < count($output); $i++) { $this->template->setDisplayDataImmediate("background_status_content", $output[$i] . "\n", $mainNode); } } else { $this->template->setDisplayDataImmediate("background_status_content", 'Process is no longer running', $mainNode); } return true; }
/** * @param mixed $obj. The calling object * @param string $script The php script * @param mixed $cl_args. String or array of string, the command line arguments. Defualts to empty arra. * @param string $wd. Workking directory. Default to null */ public static function launchBackgroundPHPScript($obj, $script, $cl_args = array(), $wd = null) { if (strlen($script) == 0) { I2CE::raiseError("No background script provided"); return false; } $script = escapeshellarg($script); $php = 'php'; if (!I2CE_FileSearch::isUnixy()) { I2CE::getConfig()->setIfIsSet($php, "/modules/BackgroundProcess/php_executable/windows"); } else { I2CE::getConfig()->setIfIsSet($php, "/modules/BackgroundProcess/php_executable/unix"); } $php = I2CE_FileSearch::realPath($php); if (!is_executable($php) && !array_key_exists('HTTP_HOST', $_SERVER) && array_key_exists('_', $_SERVER)) { //this is CLI -- try using the current running interpreter. $php = $_SERVER['_']; //this is the php executable from the CLI } $php = escapeshellarg($php); self::launchBackgroundProcess($obj, "{$php} {$script}", $cl_args, $wd); }