public function __construct($config = []) { parent::__construct(__NAMESPACE__, $config); set_time_limit(0); ini_set('memory_limit', '1024M'); $this->_Worker = new \GearmanWorker(); foreach ($this->_config['servers'] as $server) { $this->_Worker->addServer($server['host'], $server['port']); } // учитывая, что addServer всегда возвращает true, делаем дополнительный ping сервера для проверки его реакции if (!$this->_Worker->echo(self::WORKLOAD_TEST)) { throw new Exception('Не удалось соединиться с сервером'); } $this->_Db = new Db($this->_config['Db']); // последний рестарт $this->_started = $this->_Db->lastRestart(); if (!empty($this->_function)) { if (is_string($this->_function)) { $this->_Worker->addFunction($this->_function($this->_function), [$this, 'doJob']); } elseif (is_array($this->_function)) { foreach ($this->_function as $name => $callback) { $this->_Worker->addFunction($this->_function($name), is_array($callback) ? $callback : [$this, $callback]); } } } $this->_Worker->addFunction("restart_{$this->_started}", [$this, 'halt']); }
public function __construct($config = []) { parent::__construct(__NAMESPACE__, $config); $this->_Curl = new Curl\Instance(); $Db = "\\Browser\\Db\\{$this->_config['Db']['driver']}"; $this->_Db = new $Db($this->_config['Db']['config']); }
public function __construct($namespace = null, $config = []) { static::$_defaults = Hash::merge(self::$_defaults, static::$_defaults); if ($namespace) { $config = $this->_config(__NAMESPACE__, $config); } else { $namespace = __NAMESPACE__; } parent::__construct($namespace, $config); // соединение if ($this->_config['connect']) { $this->_connect(); } }
/** * Конфигурируем наш объект * * @param string $namespace пространство имён текущего вызова * @param array $config дополнительные опции * @return array конфиг готовый */ protected function _config($namespace, $config) { // это хак, который сохраняет curl options $options = !empty($config['options']) ? $config['options'] : []; unset($config['options']); $config = parent::_config($namespace, $config); if (!empty($options)) { if (empty($config['options'])) { $config['options'] = $options; } else { $config['options'] = $options + $config['options']; } } return $config; }
public function __construct($namespace = null, $connect = false, $config = array()) { $defaults = static::$_defaults; static::$_defaults = \Hash::merge(self::$_defaults, static::$_defaults); if ($namespace) { $config = $this->_config(__NAMESPACE__, $config); } else { $namespace = __NAMESPACE__; } parent::__construct($namespace, $config); static::$_defaults = $defaults; if ($connect) { $this->connect(); } if (empty($this->_table) && !empty($this->_config['table'])) { $this->_table = $this->_config['table']; } // просто соединяемся с БД return true; }
/** * Базовая инициализация. Конструктор * @param array $config опции */ public function __construct($config = array()) { parent::__construct(__NAMESPACE__, $config); }
public function __construct($config = []) { parent::__construct(__NAMESPACE__, $config); $this->_Db = new Db($this->_config['Db']); }