Exemple #1
0
 /**
  * @covers Zend\Db\Adapter\Profiler\Profiler::getProfiles
  */
 public function testGetProfiles()
 {
     $this->profiler->profilerStart('SELECT * FROM FOO1');
     $this->profiler->profilerFinish();
     $this->profiler->profilerStart('SELECT * FROM FOO2');
     $this->profiler->profilerFinish();
     $this->assertCount(2, $this->profiler->getProfiles());
 }
 public function profilerFinish()
 {
     $ret = parent::profilerFinish();
     $profile = $ret->getLastProfile();
     switch (strtolower(substr(ltrim($profile['sql']), 0, 6))) {
         case 'select':
             $queryType = static::SELECT;
             break;
         case 'insert':
             $queryType = static::INSERT;
             break;
         case 'update':
             $queryType = static::UPDATE;
             break;
         case 'delete':
             $queryType = static::DELETE;
             break;
         default:
             $queryType = static::QUERY;
             break;
     }
     $data = ['api_key' => $this->apiKey, 'type' => $queryType, 'sql' => $profile['sql'], 'start' => $profile['start'], 'end' => $profile['end'], 'elapsed' => round($profile['elapse'] * 1000 * 1000)];
     if (!empty($this->extra)) {
         $data = array_merge($this->extra, $data);
     }
     if (isset($profile['parameters'])) {
         if ($profile['parameters'] instanceof ParameterContainer) {
             $data['parameters'] = $profile['parameters']->getNamedArray();
         } elseif (is_array($profile['parameters'])) {
             $data['parameters'] = $profile['parameters'];
         }
     }
     $data['stack'] = debug_backtrace();
     $logFile = $this->logDir . '/sql-' . getmypid() . '-' . microtime(true) . '.kharon';
     file_put_contents($logFile, json_encode($data, null, 100));
 }