Example (get uptime information on a *NIX system) $p= new Process('uptime'); $uptime= $p->out->readLine(); $p->close(); var_dump($uptime);
See also: xp://lang.Runtime#getExecutable
See also: php://proc_open
Inheritance: extends Object
Exemplo n.º 1
0
    /**
     * Insert a new process.
     * @param $processType integer one of the PROCESS_TYPE_* constants
     * @param $maxParallelism integer the max. number
     *  of parallel processes allowed for the given
     *  process type.
     * @return Process the new process instance, boolean
     *  false if there are too many parallel processes.
     */
    function &insertObject($processType, $maxParallelism)
    {
        // Free processing slots occupied by zombie processes.
        $this->deleteZombies();
        // Cap the parallelism to the max. parallelism.
        $maxParallelism = min($maxParallelism, PROCESS_MAX_PARALLELISM);
        // Check whether we're allowed to spawn another process.
        $currentParallelism = $this->getNumberOfObjectsByProcessType($processType);
        if ($currentParallelism >= $maxParallelism) {
            $falseVar = false;
            return $falseVar;
        }
        // We create a process instance from the given data.
        $process = new Process();
        $process->setProcessType($processType);
        // Generate a new process ID. See classdoc for process ID
        // requirements.
        $process->setId(uniqid('', true));
        // Generate the timestamp.
        $process->setTimeStarted(time());
        // Persist the process.
        $this->update(sprintf('INSERT INTO processes
				(process_id, process_type, time_started, obliterated)
				VALUES
				(?, ?, ?, 0)'), array($process->getId(), (int) $process->getProcessType(), (int) $process->getTimeStarted()));
        $process->setObliterated(false);
        return $process;
    }
Exemplo n.º 2
0
function process_controller()
{
    //return array('content'=>"ok");
    global $mysqli, $redis, $user, $session, $route, $feed_settings;
    // There are no actions in the input module that can be performed with less than write privileges
    if (!$session['write']) {
        return array('content' => false);
    }
    $result = false;
    require_once "Modules/feed/feed_model.php";
    $feed = new Feed($mysqli, $redis, $feed_settings);
    require_once "Modules/input/input_model.php";
    $input = new Input($mysqli, $redis, $feed);
    require_once "Modules/process/process_model.php";
    $process = new Process($mysqli, $input, $feed, $user->get_timezone($session['userid']));
    if ($route->format == 'html') {
        if ($route->action == 'api') {
            $result = view("Modules/process/Views/process_api.php", array());
        }
    } else {
        if ($route->format == 'json') {
            if ($route->action == "list") {
                $result = $process->get_process_list();
            }
        }
    }
    return array('content' => $result);
}
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     try {
         $log = new Process();
         $log->name = "get-links";
         $log->status = "running";
         $log->save();
         //Check new links
         Rss::chunk(100, function ($rss) {
             foreach ($rss as $value) {
                 $this->loadRss($value);
                 $value->touch();
             }
         });
         //Remove old links
         $filterDate = new DateTime('now');
         $filterDate->sub(new DateInterval('P1D'));
         Link::where('date', '<', $filterDate)->where('updated_at', '<', $filterDate)->delete();
         $log->status = "finished";
         $log->save();
     } catch (Exception $e) {
         $this->info($url);
         $this->info($e->getMessage());
     }
 }
Exemplo n.º 4
0
 /**
  * @param $command
  * @param $string
  */
 protected function _sendCommand($command, $string)
 {
     $process = new Process($command, $this->_globalDictionary);
     $process->write($string);
     $this->_raw = $process->read();
     $process->close();
 }
 function check_job_servers()
 {
     //loop schemas
     foreach (Doo::db()->find('Schemata') as $s) {
         $schema_id = $s->id;
         //enabled config with PID
         foreach (Doo::db()->find('GearmanJobServers', array('where' => 'local = 1 AND enabled = 1 AND schema_id = ' . $schema_id)) as $js) {
             if (!empty($js->pid)) {
                 //init
                 $p = new Process();
                 $p->setPid($js->pid);
                 //check status
                 if ($p->status()) {
                     continue;
                 }
             }
             //let start
             $js->pid = $this->start_local_job_server($js->id, $js->port, $s->id);
             $js->update();
         }
         //disabled config
         foreach (Doo::db()->find('GearmanJobServers', array('where' => 'local = 1 AND enabled = 0 AND pid IS NOT NULL AND schema_id = ' . $schema_id)) as $js) {
             //stop
             $p = new Process();
             $p->setPid($js->pid);
             $p->stop();
             $js->pid = null;
             $js->update(array('setnulls' => true));
         }
     }
 }
Exemplo n.º 6
0
 /**
  * add a process
  *
  * @param Process $process
  * @param null|string $name process name
  * @return int
  */
 public function execute(Process $process, $name = null)
 {
     if (!is_null($name)) {
         $process->name($name);
     }
     $process->start();
     return array_push($this->processes, $process);
 }
Exemplo n.º 7
0
 /**
  * Tests Process::run
  */
 public function testRun()
 {
     $cmd = new Cmd('echo 1');
     $process = new Process();
     $process->addCommand($cmd);
     $res = $process->run();
     $this->assertEquals(0, $res->getCode(), 'echo should work everywhere');
 }
Exemplo n.º 8
0
 /**
  * Copies the specified hook to your repos git hooks directory only if it
  * doesn't already exist!
  * @param  string $hook the hook to copy/symlink
  * @return void
  */
 public function copy($hook)
 {
     if (false === file_exists(self::GIT_HOOKS_PATH . $hook)) {
         // exec('cp ' . __DIR__ . '/../../../../hooks/' . $hook . ' ' . GIT_HOOKS_PATH . $hook);
         $copy = new Process('cp ' . __DIR__ . '/../../../../hooks/' . $hook . ' .git/hooks/' . $hook);
         $copy->run();
     }
 }
Exemplo n.º 9
0
 /**
  * Executed once before each test method.
  */
 public function setUp()
 {
     if (self::$InitProcessToRestore === null) {
         self::$InitProcessToRestore = ProcManager::getInstance()->getCurrentProcess();
     }
     $this->fixture_file1_path = USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeFile.ext';
     $this->fixture_metafile1_path = USERS_PATH . '/john/' . USERS_METAFILES_DIR . '/' . USERS_FILES_DIR . '/myHomeFile.ext.xml';
     $this->fixture_file2_path = EYEOS_TESTS_TMP_PATH . '/mySysFile.ext';
     $this->fixture_dir1_path = USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeDir';
     $this->fixture_dir2_path = EYEOS_TESTS_TMP_PATH . '/mySysDir';
     $this->group = UMManager::getGroupByName(SERVICE_UM_DEFAULTUSERSGROUP);
     if (!self::$AliceCreated) {
         try {
             //create group "wonderland"
             $wonderland = UMManager::getInstance()->getNewGroupInstance();
             $wonderland->setName('wonderland');
             UMManager::getInstance()->createGroup($wonderland);
         } catch (EyeGroupAlreadyExistsException $e) {
         }
         try {
             //create user "alice"
             $alice = UMManager::getInstance()->getNewUserInstance();
             $alice->setName('alice');
             $alice->setPassword('alice', true);
             $alice->setPrimaryGroupId($wonderland->getId());
             UMManager::getInstance()->createUser($alice);
         } catch (EyeUserAlreadyExistsException $e) {
         }
         self::$AliceCreated = true;
     }
     AdvancedPathLib::rmdirs(USERS_PATH . '/john/' . USERS_FILES_DIR, true);
     AdvancedPathLib::rmdirs(USERS_PATH . '/john/' . USERS_METAFILES_DIR, true);
     if (!is_dir(EYEOS_TESTS_TMP_PATH)) {
         mkdir(EYEOS_TESTS_TMP_PATH, 0777, true);
     }
     AdvancedPathLib::rmdirs(EYEOS_TESTS_TMP_PATH, true);
     $this->fixture_file1 = FSI::getFile('home://~john/myHomeFile.ext');
     file_put_contents($this->fixture_file1_path, 'some content');
     $this->fixture_file2 = FSI::getFile('sys:///tests/tmp/mySysFile.ext');
     file_put_contents($this->fixture_file2_path, 'some other content');
     $this->fixture_dir1 = FSI::getFile('home://~john/myHomeDir');
     if (!is_dir($this->fixture_dir1_path)) {
         mkdir($this->fixture_dir1_path);
     }
     $this->fixture_dir2 = FSI::getFile('sys:///tests/tmp/mySysDir');
     if (!is_dir($this->fixture_dir2_path)) {
         mkdir($this->fixture_dir2_path);
     }
     $proc = new Process('example');
     $loginContext = new LoginContext('example', new Subject());
     $loginContext->getSubject()->getPrivateCredentials()->append(new EyeosPasswordCredential('john', 'john'));
     $loginContext->login();
     $proc->setLoginContext($loginContext);
     ProcManager::getInstance()->execute($proc);
     self::$MyProcPid = $proc->getPid();
 }
Exemplo n.º 10
0
 protected function detectProcessorNumberByGrep()
 {
     if (Utils::findBin('grep') && file_exists('/proc/cpuinfo')) {
         $process = new Process('grep -c ^processor /proc/cpuinfo 2>/dev/null');
         $process->run();
         $this->processorNumber = intval($process->getOutput());
         return $this->processorNumber;
     }
     return;
 }
Exemplo n.º 11
0
 /** @Decorated */
 public function test_save_form()
 {
     $pro = new Process();
     $pro->setProcessID($this->input->post("ProcessID"));
     $pro->setGroupID($this->input->post("GroupID"));
     $pro->setProcessName($this->input->post("ProcessName"));
     $this->load->model("process_manager");
     $this->process_manager->save($pro);
     //echo "OK";
 }
Exemplo n.º 12
0
 /**
  * getting default list
  *
  * @param string $httpData (opional)
  */
 public function index($httpData)
 {
     if ($this->userUxType == 'SINGLE') {
         $this->indexSingle($httpData);
         return;
     }
     require_once 'classes/model/UsersProperties.php';
     G::LoadClass('process');
     G::LoadClass('case');
     $userProperty = new UsersProperties();
     $process = new Process();
     $case = new Cases();
     G::loadClass('system');
     $sysConf = System::getSystemConfiguration(PATH_CONFIG . 'env.ini');
     //Get ProcessStatistics Info
     $start = 0;
     $limit = '';
     $proData = $process->getAllProcesses($start, $limit);
     $processList = $case->getStartCasesPerType($_SESSION['USER_LOGGED'], 'category');
     $switchLink = $userProperty->getUserLocation($_SESSION['USER_LOGGED']);
     if (!isset($_COOKIE['workspaceSkin'])) {
         if (substr($sysConf['default_skin'], 0, 2) == 'ux') {
             $_SESSION['_defaultUserLocation'] = $switchLink;
             $switchLink = '/sys' . SYS_SYS . '/' . SYS_LANG . '/' . $sysConf['default_skin'] . '/main';
         }
     }
     unset($processList[0]);
     //Get simplified options
     global $G_TMP_MENU;
     $mnu = new Menu();
     $mnu->load('simplified');
     $arrayMnuOption = array();
     $mnuNewCase = array();
     if (!empty($mnu->Options)) {
         foreach ($mnu->Options as $index => $value) {
             $option = array('id' => $mnu->Id[$index], 'url' => $mnu->Options[$index], 'label' => $mnu->Labels[$index], 'icon' => $mnu->Icons[$index], 'class' => $mnu->ElementClass[$index]);
             if ($mnu->Id[$index] != 'S_NEW_CASE') {
                 $arrayMnuOption[] = $option;
             } else {
                 $mnuNewCase = $option;
             }
         }
     }
     $this->setView($this->userUxBaseTemplate . PATH_SEP . 'index');
     $this->setVar('usrUid', $this->userID);
     $this->setVar('userName', $this->userName);
     $this->setVar('processList', $processList);
     $this->setVar('canStartCase', $case->canStartCase($_SESSION['USER_LOGGED']));
     $this->setVar('userUxType', $this->userUxType);
     $this->setVar('clientBrowser', $this->clientBrowser['name']);
     $this->setVar('switchLink', $switchLink);
     $this->setVar('arrayMnuOption', $arrayMnuOption);
     $this->setVar('mnuNewCase', $mnuNewCase);
     $this->render();
 }
Exemplo n.º 13
0
 public function processRequest(MMapRequest $request, MMapResponse $response)
 {
     $oauth_verifier = null;
     $oauth_token = null;
     if ($request->issetGET('oauth_verifier')) {
         $oauth_verifier = $request->getGET('oauth_verifier');
     }
     if ($request->issetGET('oauth_token')) {
         $oauth_token = $request->getGET('oauth_token');
     }
     if ($oauth_verifier && $oauth_token) {
         $response->getHeaders()->append('Content-type: text/html');
         $body = '<html>
                         <div id="logo_eyeos" style="margin: 0 auto;width:350"> <img src="eyeos/extern/images/logo-eyeos.jpg"/></div>
                         <div style="margin: 0 auto;width:350;text-align:center"><span style="font-family:Verdana;font-size:20px;">Successful authentication.<br>Back to Eyeos.</span></div>
                  </html>';
         $response->getHeaders()->append('Content-Length: ' . strlen($body));
         $response->getHeaders()->append('Accept-Ranges: bytes');
         $response->getHeaders()->append('X-Pad: avoid browser bug');
         $response->getHeaders()->append('Cache-Control: ');
         $response->getHeaders()->append('pragma: ');
         $response->setBody($body);
         try {
             $userRoot = UMManager::getInstance()->getUserByName('root');
         } catch (EyeNoSuchUserException $e) {
             throw new EyeFailedLoginException('Unknown user root"' . '". Cannot proceed to login.', 0, $e);
         }
         $subject = new Subject();
         $loginContext = new LoginContext('eyeos-login', $subject);
         $cred = new EyeosPasswordCredential();
         $cred->setUsername('root');
         $cred->setPassword($userRoot->getPassword(), false);
         $subject->getPrivateCredentials()->append($cred);
         $loginContext->login();
         Kernel::enterSystemMode();
         $appProcess = new Process('stacksync');
         $appProcess->setPid('31338');
         $mem = MemoryManager::getInstance();
         $processTable = $mem->get('processTable', array());
         $processTable[31338] = $appProcess;
         $mem->set('processTable', $processTable);
         $appProcess->setLoginContext($loginContext);
         ProcManager::getInstance()->setCurrentProcess($appProcess);
         kernel::exitSystemMode();
         $token = new stdClass();
         $token->oauth_verifier = $oauth_verifier;
         $token->oauth_token = $oauth_token;
         $group = UMManager::getInstance()->getGroupByName('users');
         $users = UMManager::getInstance()->getAllUsersFromGroup($group);
         foreach ($users as $user) {
             $NetSyncMessage = new NetSyncMessage('cloud', 'token', $user->getId(), $token);
             NetSyncController::getInstance()->send($NetSyncMessage);
         }
     }
 }
Exemplo n.º 14
0
 /** @Decorated */
 public function save_object($object_name)
 {
     if ($object_name == "Process") {
         $pro = new Process();
         $pro->setProcessID($this->input->post("ProcessID"));
         $pro->setGroupID($this->input->post("GroupID"));
         $pro->setProcessName($this->input->post("ProcessName"));
         $this->load->model("process_manager");
         $this->process_manager->save($pro);
     }
     $this->output->set_output("Save " . $object_name . " successfully!");
 }
Exemplo n.º 15
0
 public function setUp()
 {
     if (self::$InitProcessToRestore === null) {
         self::$InitProcessToRestore = ProcManager::getInstance()->getCurrentProcess();
     }
     $this->config = new XMLAuthConfiguration(SYSTEM_CONF_PATH . '/' . SERVICES_DIR . '/' . SERVICE_UM_DIR . '/' . SERVICE_UM_AUTHCONFIGURATIONS_DIR . '/eyeos_default.xml');
     $this->loginContext = new LoginContext('eyeos-login', new Subject(), $this->config);
     $this->loginContext->getSubject()->getPrivateCredentials()->append(new EyeosPasswordCredential('john', 'john'));
     $this->loginContext->login();
     $proc = new Process('init');
     $proc->setLoginContext($this->loginContext);
     ProcManager::getInstance()->execute($proc);
     self::$MyProcPid = $proc->getPid();
 }
Exemplo n.º 16
0
 /**
  * start new processes if needed
  *
  * @return int num of job
  */
 public function tick()
 {
     if ($this->countPool() < 1 && $this->countJob()) {
         $job = $this->getJob();
         if ($job) {
             $szal = new Process($this->worker);
             $szal->setLifeTime(4);
             //NOTICE
             $this->pool[] = $szal;
             $szal->start($job);
         }
     }
     return $this->countJob();
 }
Exemplo n.º 17
0
 /**
  * @param $cmd
  * @param array $processOptions
  * @return Process
  */
 public function execute($cmd, $processOptions = array())
 {
     // @todo
     // this thing is only there to avoid outputing config commands
     // will have to go once #12539 is fixed
     if (!(isset($this->options['skip_output']) && preg_match($this->options['skip_output'], $cmd))) {
         $this->output(sprintf("-!- %s", $cmd));
     }
     $full_cmd = sprintf($this->options['format'], $cmd);
     $this->output(sprintf("-!- (DEBUG) %s", $full_cmd), Output::SCOPE_DEBUG);
     $proc = new Process($full_cmd, array_merge($this->processOptions, $processOptions));
     $proc->execute();
     return $proc;
 }
Exemplo n.º 18
0
 function ProcessRequest()
 {
     require_once GTFW_APP_DIR . 'module/gtfw_menu/response/Process.proc.class.php';
     $Proc = new Process();
     $post = $_POST->AsArray();
     $result = $Proc->input();
     if ($result == true) {
         Messenger::Instance()->Send('gtfw_menu', 'menu', 'view', 'html', array(NULL, 'Penambahan data berhasil', 'notebox-done'), Messenger::NextRequest);
         $redirect = Dispatcher::Instance()->GetUrl('gtfw_menu', 'menu', 'view', 'html') . '&display';
     } else {
         Messenger::Instance()->Send('gtfw_menu', 'input', 'view', 'html', array($post, implode('<br/>', $Proc->err_msg), 'notebox-warning'), Messenger::NextRequest);
         $redirect = Dispatcher::Instance()->GetUrl('gtfw_menu', 'add', 'view', 'html');
     }
     $this->RedirectTo($redirect);
 }
 public function __construct(\lib\Webos $webos, \lib\Authorization $auth, $class, $method)
 {
     //On appelle le constructeur du parent.
     parent::__construct($webos, $auth);
     $this->className = $class;
     $this->methodName = $method;
 }
Exemplo n.º 20
0
 protected function getData()
 {
     $data = parent::getData();
     $data["class"] = get_class($this);
     $data["matcher"] = $this->getMatcher();
     return $data;
 }
Exemplo n.º 21
0
 /**
  * __construct
  *
  * Class constructor, appends Module settings to default settings
  *
  */
 public function __construct()
 {
     $this->setSettings(__CLASS__, parse_ini_file(strtolower(__CLASS__) . '.ini.php', true));
     //set the plugin link and the icon for the menubar
     self::$name = "Process";
     self::$icon = "fa-file";
 }
Exemplo n.º 22
0
 /**
  * Invoke filter
  * @param string $code
  * @param \WebLoader\Compiler $loader
  * @param string $file
  * @return string
  */
 public function __invoke($code, \WebLoader\Compiler $loader, $file)
 {
     if (pathinfo($file, PATHINFO_EXTENSION) === 'less') {
         $code = Process::run("{$this->bin} -", $code, dirname($file), $this->env);
     }
     return $code;
 }
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->removeByName('Order');
        $fields->removeByName('ProcessInfo');
        $fields->removeByName('ProcessStages');
        $processParent = Process::get();
        if ($processParent) {
            $fields->insertAfter(new DropdownField('ParentID', 'Belongs to this Process', $processParent->map('ID', 'Title')), 'Title');
        }
        $fields->addFieldToTab('Root.Main', $processSteps = new CompositeField(new GridField('ProcessInfo', 'Information for this stage', $this->ProcessInfo(), GridFieldConfig_RelationEditor::create())));
        $fields->insertBefore(new LiteralField('StageTitle', '<h3 class="process-info-header">
			<span class="step-label">
				<span class="flyout">1.1</span><span class="arrow"></span>
				<span class="title">Stop stage details</span>
			</span>
		</h3>'), 'Title');
        $fields->insertBefore(new LiteralField('StageTitle', '<h3 class="process-info-header">
			<span class="step-label">
				<span class="flyout">1.2</span><span class="arrow"></span>
				<span class="title">Final information</span>
			</span>
		</h3>'), 'ProcessInfo');
        return $fields;
    }
Exemplo n.º 24
0
 /**
  * Runs the process.
  *
  * @param Closure|string|array $callback A PHP callback to run whenever there is some
  *                                       output available on STDOUT or STDERR
  *
  * @return integer The exit status code
  *
  * @api
  */
 public function run($callback = null)
 {
     if (null === $this->getCommandLine()) {
         $this->setCommandLine($this->getPhpBinary());
     }
     return parent::run($callback);
 }
Exemplo n.º 25
0
 /**
  * Forks and run the process.
  *
  * @param Closure|string|array $callback A PHP callback to run whenever there is some
  *                                       output available on STDOUT or STDERR
  *
  * @return integer The exit status code
  */
 public function run($callback = null)
 {
     if (null === $this->commandline) {
         $this->commandline = $this->getPhpBinary();
     }
     parent::run($callback);
 }
Exemplo n.º 26
0
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->removeByName('Order');
        $fields->removeByName('Title');
        $fields->removeByName('ProcessInfo');
        $fields->removeByName('ParentProcessID');
        $fields->addFieldToTab('Root.Main', $processSteps = new CompositeField($title = new TextField('Title', 'Title')));
        $title->addExtraClass('process-noborder');
        $processSteps->addExtraClass('process-step');
        $fields->addFieldToTab('Root.Main', $processSteps = new CompositeField(new GridField('ProcessInfo', 'Information for this case', $this->ProcessInfo(), GridFieldConfig_RecordViewer::create())));
        $processes = Process::get();
        if ($processes) {
            $fields->insertAfter($inner = new CompositeField(new LiteralField('ExplainStop', '<label class="right">This must be set after you create a process</label>'), $processesOptions = new DropdownField('ParentProcessID', 'Process', $processes->map('ID', 'Title'))), 'Title');
            $inner->addExtraClass('message special');
        }
        $processSteps->addExtraClass('process-step');
        $fields->insertBefore(new LiteralField('StageTitle', '<h3 class="process-info-header">
				<span class="step-label">
					<span class="flyout">0.1</span><span class="arrow"></span>
					<span class="title">Case details</span>
				</span>
			</h3>'), 'Title');
        $fields->insertBefore(new LiteralField('StageTitle', '<h3 class="process-info-header">
				<span class="step-label">
					<span class="flyout">0.2</span><span class="arrow"></span>
					<span class="title">Associated Information Pieces</span>
				</span>
			</h3>'), 'ProcessInfo');
        return $fields;
    }
Exemplo n.º 27
0
 public function __construct(Logger $logger, $ipcSock, Bootstrapper $bootstrapper = null)
 {
     parent::__construct($logger);
     $this->logger = $logger;
     $this->ipcSock = $ipcSock;
     $this->bootstrapper = $bootstrapper ?: new Bootstrapper();
 }
Exemplo n.º 28
0
 /**
  * @param string
  * @param bool|NULL
  * @return string
  */
 public function compileCoffee($source, $bare = NULL)
 {
     if (is_null($bare)) {
         $bare = $this->bare;
     }
     $cmd = $this->bin . ' -p -s' . ($bare ? ' -b' : '');
     return Process::run($cmd, $source);
 }
Exemplo n.º 29
0
 /**
  * Invoke filter
  *
  * @param string
  * @param \WebLoader\Compiler
  * @param string
  * @return string
  */
 public function __invoke($code, \WebLoader\Compiler $loader, $file = NULL)
 {
     if (pathinfo($file, PATHINFO_EXTENSION) === 'styl') {
         $cmd = $this->bin . ($this->compress ? ' -c' : '');
         $code = Process::run($cmd, $code);
     }
     return $code;
 }
Exemplo n.º 30
0
 public function __construct(Logger $logger)
 {
     parent::__construct($logger);
     $this->logger = $logger;
     $this->procGarbageWatcher = \Amp\repeat(function () {
         $this->collectProcessGarbage();
     }, 100, ["enable" => false]);
 }