コード例 #1
0
ファイル: Run.php プロジェクト: miaokuan/simdp
 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}]");
 }
コード例 #2
0
ファイル: Db.php プロジェクト: miaokuan/simdp
 /**
  * Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a MySQLi_Result object. For other successful queries mysqli_query() will return TRUE.
  */
 public function query($sql)
 {
     $this->lastSql = $sql;
     $begin = intval(microtime(true) * 1000000);
     $this->connect();
     $res = $this->mysqli->query($sql);
     #reconnect max times 3
     for ($i = 0; $i < 3; $i++) {
         if (in_array($this->mysqli->errno, $this->retryErrno)) {
             Log::warning("db reconnect. [errno:" . $this->mysqli->errno . " error:" . $this->mysqli->error . " sql:{$sql}]");
             usleep(100000);
             $this->connect(true);
             $res = $this->mysqli->query($sql);
         } else {
             break;
         }
     }
     if (false === $res) {
         Log::warning("db error. [errno:" . $this->mysqli->errno . " error:" . $this->mysqli->error . " sql: {$sql}]");
     }
     $this->lastCost = intval(microtime(true) * 1000000) - $begin;
     $this->totalCost += $this->lastCost;
     Log::debug('query success. [cost: ' . $this->lastCost . 'us] [sql: ' . $sql . ']');
     return $res;
 }