Ejemplo n.º 1
0
 public function openDebug()
 {
     $registry = Registry::getInstance();
     $registry->debug = true;
     $storage = null;
     if ($mc_config = $registry->memcache_config) {
         $storage = new CacheStorage($mc_config['host'], $mc_config['port']);
     }
     $clockwork = Monitor::getClockwork($storage);
     Router::getInstance()->get('/__clockwork/(.*)', function ($request, $id) use($clockwork) {
         header('Content-Type: application/json');
         echo $clockwork->getStorage()->retrieveAsJson($id);
         exit;
     });
     Monitor::getInstance()->startEvent('App Request', 'Total Time Costs.');
 }
Ejemplo n.º 2
0
 protected function run($ch)
 {
     curl_setopt($ch, CURLOPT_URL, $this->url);
     if ($this->withHeader) {
         curl_setopt($ch, CURLOPT_HEADER, 1);
     }
     $response = curl_exec($ch);
     if ($response === false) {
         $this->error = ['errno' => curl_errno($ch), 'error' => curl_error($ch)];
         App::getInstance()->getLogger()->error('curl: ' . $this->url . ',' . curl_error($ch));
     } else {
         $this->info = curl_getinfo($ch);
         if (Registry::getInstance()->debug) {
             $middleware = Monitor::getInstance();
             $middleware->httpRequest($this->info['url'], $this->info['total_time'], $this->query ? $this->query : '');
         }
     }
     curl_close($ch);
     return $response;
 }
Ejemplo n.º 3
0
 public static function logging($query, $time)
 {
     Monitor::getInstance()->dbQuery($query, $time);
 }
Ejemplo n.º 4
0
 /**
  * Execute the router: Loop all defined before middlewares and routes, and execute the handling function if a match was found.
  *
  * @param object|callable $callback Function to be executed after a matching route was handled (= after router middleware)
  */
 public function run($callback = null)
 {
     $method = Request::getInstance()->getMethod();
     $handled = false;
     if (isset(static::$routes[$method])) {
         $handled = $this->handle(static::$routes[$method]);
     }
     if (!$handled) {
         // Handle 404
         $notFound = $this->notFound;
         if (!$notFound) {
             Response::getInstance()->abort(404);
         }
         if (is_array($notFound)) {
             $notFound[0] = new $notFound[0]();
         }
         if (!is_callable($notFound)) {
             Response::getInstance()->abort(404);
         }
         call_user_func($notFound);
     } else {
         // After router middleware
         if (is_string($callback) && strstr($callback, '@')) {
             $callback = explode('@', $callback);
             $callback[0] = new $callback[0]();
             call_user_func($callback);
         } elseif ($callback) {
             $callback();
         }
     }
     // If it originally was a HEAD request, clean up after ourselves by emptying the output buffer
     if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {
         ob_end_clean();
     }
     if (Registry::getInstance()->debug) {
         Monitor::getInstance()->endEvent('App Request');
     }
 }