コード例 #1
0
 /**
  * Setup.
  *
  * @param string $config Gearman configuration name
  */
 protected function setup($config = 'default')
 {
     $this->setttings = Gearman::config($config);
     if (!isset($this->setttings)) {
         throw new ConfigException("{$config} is not a valid li3_gearman configuration");
     } elseif (empty($this->setttings['servers'])) {
         throw new ConfigException("{$config} defines no servers");
     }
     if (!empty($this->memlimit)) {
         $units = ['K' => 1024, 'M' => 1024 * 1024, 'G' => 1024 * 1024 * 1024];
         $memoryLimit = ini_get('memory_limit');
         $memoryLimit = (int) substr($memoryLimit, 0, -1) * $units[$memoryLimit[strlen($memoryLimit) - 1]];
         $this->settings['memoryLimit'] = (int) floor($memoryLimit * ($this->memlimit / 100));
     }
     if (isset($this->environment)) {
         Environment::set($this->environment);
     } else {
         $this->environment = Environment::get();
         if (!$this->environment) {
             throw new ConfigException("Could not determine environment");
         }
     }
     foreach ([SIGTERM, SIGHUP] as $signal) {
         if (!pcntl_signal($signal, [$this, 'signal'])) {
             throw new RuntimeException("Could not register signal {$signal}");
         }
     }
 }