public function run() { $pid = $this->mypid; $app = $this->app; $action = $this->action . 'Action'; Log::info("Begin to execute. [app:{$app} action:{$action} pid:{$pid}]"); $class = $this->format($app); if (!class_exists($class)) { Log::fatal("Failed to find class:{$class}"); return; } $obj = new $class($this->params); if (!method_exists($obj, $action)) { Log::fatal("Failed to find method:{$action}"); return; } Log::info("Calling method[{$action}] for {$app}."); $log = array(); $result = $obj->{$action}($log); //log if (!empty($log)) { foreach ($log as $l) { if (!is_scalar($l)) { $l = explode("\n", trim(print_r($l, true))); } elseif (strlen($l) > 256) { $l = substr($l, 0, 256) . '...(truncated)'; } if (is_array($l)) { foreach ($l as $ln) { Log::info($ln); } } else { Log::info($l); } } } //result if (!is_scalar($result)) { $result = explode("\n", trim(print_r($result, true))); } elseif (strlen($result) > 256) { $result = substr($result, 0, 256) . '...(truncated)'; } if (is_array($result)) { foreach ($result as $ln) { Log::debug($ln); } } else { Log::debug($result); } Log::info("Execute finished. [app:{$app} action:{$action} process id:{$pid}]"); }
protected function connect($force = false) { if ($force || !$this->isConnected) { $config = $this->config; $port = empty($config['port']) ? 3306 : $config['port']; $charset = empty($config['charset']) ? 'utf8' : $config['charset']; $socket = null; $flag = null; if (isset($config['flag'])) { $flag = $config['flag']; } $this->isConnected = $this->mysqli->real_connect($config['host'], $config['user'], $config['password'], $config['database'], $port, $socket, $flag); if (!$this->isConnected) { Log::fatal('db connect error. [errno:' . mysqli_connect_errno() . ' error:' . mysqli_connect_error() . ']'); } else { $this->mysqli->set_charset($charset); } } return $this->isConnected; }