示例#1
0
 public function resolve(Request $req, Response $res)
 {
     $req->user = new User();
     // User from CLI
     switch ($req->client('type')) {
         case 'cli':
             // Retrieve user context from process data, then CLI argument.
             $userId = (int) Process::get('type');
             if (!$userId) {
                 $req->cli()->options('u', array('alias' => 'user', 'type' => 'integer', 'describe' => 'Idenitfier of target context user.'));
                 $userId = (int) $req->meta('user');
             }
             if ($userId) {
                 $req->user->load($userId);
             }
             unset($userId);
             break;
         default:
             // Session ID provided, validate it.
             $sid = $req->meta('sid');
             if ($sid) {
                 $ret = Session::ensure($sid, $req->meta('token'), $req->fingerprint());
                 // Session doesn't exist, delete the cookie.
                 if ($ret === false || $ret === Session::ERR_EXPIRED) {
                     $res->cookie('__sid', '', time() - 3600);
                 } else {
                     if (is_integer($ret)) {
                         switch ($ret) {
                             // note: System should treat as public user.
                             case Session::ERR_INVALID:
                                 break;
                         }
                     } else {
                         // Success, proceed.
                         $req->user->load(Session::current('username'));
                         unset($req->user->password);
                     }
                 }
             } else {
                 if ($this->setupSession && !@\core\Node::get('User')) {
                     $req->user->data(['id' => 0, 'groups' => ['Administrators'], 'username' => '__default']);
                 }
             }
             break;
     }
 }
示例#2
0
    unset($res, $pids);
    if ($affectedRows) {
        Log::debug(sprintf('Process cleanup, %d processes removed.', $affectedRows));
    }
    die;
}
// Cron processes
if (@$opts['cron']) {
    Log::debug('Cron started process.');
    $scheduler = function ($schedule) {
        $nextTime = CronExpression::factory($schedule['schedule'])->getNextRunDate()->format('Y-m-d H:i:s');
        /*! Note
         *  The purpose of schedule_name alias is to use a less common name, and
         *  leave the "name" property open for in-process use.
         */
        $schedules = Node::get(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS, 'start_time' => $nextTime, 'command' => $schedule['command'], 'schedule_name' => $schedule['name']));
        if (!$schedules) {
            $schedule = ['command' => $schedule['command'], 'start_time' => $nextTime, 'schedule_name' => $schedule['name'], '$type' => 'cron', '$spawn' => false];
            Log::debug('Scheduling new process', $schedule);
            Process::enqueue($schedule['command'], $schedule);
        }
    };
    // Configuration based crontab
    array_map($scheduler, (array) conf::get('crontab::schedules'));
}
// Avoid forking connection crash, renew the connection.
Database::disconnect();
// Forks then exits the parent.
// Use nohup if internal forking is not supported.
if (!function_exists('pcntl_fork')) {
    $ret = shell_exec('nohup ' . Process::EXEC_PATH . ' --nohup >/dev/null 2>&1 & echo $!');
示例#3
0
 /**
  * Retrieve process related info by specified property $name.
  *
  * @param {string} $name Target property in process object, omit this to get the whole object.
  */
 public static function get($name = null)
 {
     if (constant('PHP_SAPI') != 'cli' || !function_exists('posix_getppid')) {
         return null;
     }
     $processData =& self::$_processData;
     if (!$processData) {
         $processData = Node::get(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS, 'pid' => [getmypid(), posix_getppid()]));
         $processData = util::unwrapAssoc($processData);
     }
     if (is_null($name)) {
         return $processData;
     } else {
         return @$processData[$name];
     }
 }
示例#4
0
 /**
  * @private
  *
  * Load resources of specified key into cache.
  */
 private function loadCache($identifier)
 {
     $cache =& $this->localeCache[$identifier];
     if (!$cache) {
         $cache = Node::get(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_TRANSLATION, 'identifier' => $identifier, 'locale' => $this->localeChain));
         // Sorts by locale with localChain
         usort($cache, function ($subject, $object) {
             $subject = array_search($subject['locale'], $this->localeChain);
             $object = array_search($object['locale'], $this->localeChain);
             if ($subject == $object) {
                 return 0;
             } else {
                 return $subject > $object ? 1 : -1;
             }
         });
     }
     return $cache;
 }