예제 #1
0
파일: Session.php 프로젝트: aoyel/angel
 public function start()
 {
     if ($this->isStart()) {
         return;
     }
     @session_start();
     if ($this->isStart()) {
         Angel::info('Session started', __METHOD__);
     } else {
         $error = error_get_last();
         $message = isset($error['message']) ? $error['message'] : 'Failed to start session.';
         Angel::error($message, __METHOD__);
     }
 }
예제 #2
0
 /**
  * Main iterator
  *
  * * @return boolean 0|1
  */
 private final function loop()
 {
     if (file_put_contents($this->getPidPath(), getmypid())) {
         $this->parentPID = getmypid();
         $this->saveLog('Daemon ' . $this->shortName . ' pid ' . getmypid() . ' started.');
         Angel::debug('Daemon ' . $this->shortName . ' pid ' . getmypid() . ' started.');
         while (!self::$stopFlag && memory_get_usage() < $this->memoryLimit) {
             $this->trigger(self::EVENT_BEFORE_ITERATION);
             $jobs = $this->defineJobs();
             $this->saveLog("get job list is :" . var_export($jobs, true));
             if ($jobs && count($jobs)) {
                 while (($job = $this->defineJobExtractor($jobs)) !== null) {
                     $this->saveLog("current run job is :{$job}");
                     // if no free workers, wait
                     if (count(static::$currentJobs) >= $this->maxChildProcesses) {
                         $this->saveLog('Reached maximum number of child processes. Waiting...');
                         Angel::debug('Reached maximum number of child processes. Waiting...');
                         while (count(static::$currentJobs) >= $this->maxChildProcesses) {
                             sleep(1);
                             pcntl_signal_dispatch();
                         }
                         Angel::debug('Free workers found: ' . ($this->maxChildProcesses - count(static::$currentJobs)) . ' worker(s). Delegate tasks.');
                     }
                     pcntl_signal_dispatch();
                     $this->runDaemon($job);
                 }
                 $this->saveLog("jobs was finished");
             } else {
                 sleep($this->sleep);
             }
             pcntl_signal_dispatch();
             $this->trigger(self::EVENT_AFTER_ITERATION);
         }
         if (memory_get_usage() < $this->memoryLimit) {
             Angel::debug('Daemon ' . $this->shortName . ' pid ' . getmypid() . ' used ' . memory_get_usage() . ' bytes on ' . $this->memoryLimit . ' bytes allowed by memory limit');
         }
         $this->saveLog('Daemon ' . $this->shortClassName() . ' pid ' . getmypid() . ' is stopped.');
         Angel::info('Daemon ' . $this->shortClassName() . ' pid ' . getmypid() . ' is stopped.');
         if (file_exists($this->getPidPath())) {
             @unlink($this->getPidPath());
         } else {
             Angel::error('Can\'t unlink pid file ' . $this->getPidPath());
         }
         return self::EXIT_CODE_NORMAL;
     }
     $this->halt(self::EXIT_CODE_ERROR, 'Can\'t create pid file ' . $this->getPidPath());
 }