Error Info: php_network_getaddresses: getaddrinfo failed: Name or service not known
$this->executeCommand('AUTH', [$this->password]); } if ($this->database !== null) { $this->executeCommand('SELECT', [$this->database]); } $this->initConnection(); } else { \Yii::error("Failed to open redis DB connection ($connection): $errorNumber - $errorDescription", __CLASS__); $message = YII_DEBUG ? "Failed to open redis DB connection ($connection): $errorNumber - $errorDescription" : 'Failed to open DB connection.'; throw new Exception($message, $errorDescription, $errorNumber); } } /** * Closes the currently active DB connection. * It does nothing if the connection is already closed. */ public function close() {
* See [redis protocol description](http://redis.io/topics/protocol) * for details on the mentioned reply types. * @throws Exception for commands that return [error reply](http://redis.io/topics/protocol#error-reply). */ public function executeCommand($name, $params = []) { $this->open(); $params = array_merge(explode(' ', $name), $params); $command = '*' . count($params) . "\r\n"; foreach ($params as $arg) { $command .= '$' . mb_strlen($arg, '8bit') . "\r\n" . $arg . "\r\n"; }
protected function getValue ($key) { \Yii::beginProfile('Redis_' . $key); $value = $this->redis->executeCommand('GET', [ $key ]); \Yii::endProfile('Redis_' . $key); return $value; }
* @return mixed the value stored in cache, false if the value is not in the cache, expired, * or the dependency associated with the cached data has changed. */ public function get($key) { $key = $this->buildKey($key); $value = $this->getValue($key); if ($value === false || $this->serializer === false) { return $value; } elseif ($this->serializer === null) { $value = unserialize($value); } else { $value = call_user_func($this->serializer[1], $value);
if (is_string($this->cache)) { $this->cache = Yii::$app->get($this->cache, false); } if ($this->cache instanceof CacheInterface) { $cacheKey = $this->cacheKey; $hash = md5(json_encode([$this->ruleConfig, $this->rules])); if (($data = $this->cache->get($cacheKey)) !== false && isset($data[1]) && $data[1] === $hash) { $this->rules = $data[0]; } else { $this->rules = $this->buildRules($this->rules); $this->cache->set($cacheKey, [$this->rules, $hash]); } } else {
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
return $reflection->newInstanceArgs($dependencies); } if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies); } $object = $reflection->newInstanceArgs($dependencies); foreach ($config as $name => $value) { $object->$name = $value; }
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
{ if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return static::$container->invoke($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); }
if (isset($this->_definitions[$id])) { $definition = $this->_definitions[$id]; if (is_object($definition) && !$definition instanceof Closure) { return $this->_components[$id] = $definition; } return $this->_components[$id] = Yii::createObject($definition); } elseif ($throwException) { throw new InvalidConfigException("Unknown component ID: $id"); } return null; }
* Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. * The parent module may be the application. */ public function get($id, $throwException = true) { if (!isset($this->module)) { return parent::get($id, $throwException); } $component = parent::get($id, false); if ($component === null) { $component = $this->module->get($id, $throwException); }
/** * Returns the URL manager for this application. * @return \yii\web\UrlManager the URL manager for this application. */ public function getUrlManager() { return $this->get('urlManager'); } /** * Returns the internationalization (i18n) component. * @return \yii\i18n\I18N the internationalization application component. */
// delay attaching event handler to the view component after it is fully configured $app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) { $app->getView()->on(View::EVENT_END_BODY, [$this, 'renderToolbar']); $app->getResponse()->on(Response::EVENT_AFTER_PREPARE, [$this, 'setDebugHeaders']); }); $app->getUrlManager()->addRules([ [ 'class' => 'yii\web\UrlRule', 'route' => $this->id, 'pattern' => $this->id, ], [
if (!isset($component)) { $component = Yii::createObject($mixed); } if ($component instanceof BootstrapInterface) { Yii::trace('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__); $component->bootstrap($this); } else { Yii::trace('Bootstrap with ' . get_class($component), __METHOD__); } } }
protected function bootstrap() { $request = $this->getRequest(); Yii::setAlias('@webroot', dirname($request->getScriptFile())); Yii::setAlias('@web', $request->getBaseUrl()); parent::bootstrap(); } /** * Handles the specified request. * @param Request $request the request to be handled * @return Response the resulting response
/** * @inheritdoc */ public function init() { $this->state = self::STATE_INIT; $this->bootstrap(); } /** * Initializes extensions and executes bootstrap components. * This method is called by [[init()]] after the application has been fully configured. * If you override this method, make sure you also call the parent implementation.
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
$this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); } /** * Pre-initializes the application. * This method is called at the beginning of the application constructor. * It initializes several important application properties.
__DIR__ . '/../config/toutiao/main.php', __DIR__ . '/../config/toutiao/main-local.php', __DIR__ . '/../config/main-modules.php', ], $config, true); Yii::endProfile('加载配置文件'); $application = new \common\web\Application($config); // Application初始化完成后执行的一些程序 after_application_init(); $application->run();