public function validate() {/*{{{*/ $debugger = new Debugger(); $memcacheTime = $msg = ''; foreach ($this->hosts as $memcache) { $start = $debugger->getTimeStamp(); $m = new Memcached; $m->addServer($memcache['host'], $memcache['port']); $m->set('monitortest', 'haha', 10); $res = $m->get('monitortest'); $end = $debugger->getTimeStamp(); $diff = $debugger->timeDiff($start, $end); $key = $memcache['host'].':'.$memcache['port']; if (false == $res || 'haha' != $res) { $msg .= $key.'memcacheʧЧ,'; } if ($this->maxConnectTime < $diff) { $msg .= $key.'Á¬½Ó'.substr($diff, 0, 6).'ms,'; } $memcacheTime .= "$diff "; } error_log(date('Y-m-d H:i:s').' '.rtrim($memcacheTime)."\n", 3, '/tmp/memcache_time.log'); if ($msg) { error_log(date('Y-m-d H:i:s').' '.$msg."\n", 3, '/tmp/memcache.log'); } return $msg; }/*}}}*/
/** * @param bool|false $flag * @return $this */ public function setDebugEnabled($flag = false) { if (!$this->_debugger) { //只有在debug开启时才实例化debugger,并且不能置于构造方法中,否则形成死循环 $this->_debugger = Debugger::getInstance(); } $this->_debugger->setEnabled($flag); return $this; }
/** * add method * * @return void */ public function add() { if ($this->request->is('post')) { //Check to see if the user has selected a file $this->Upload->set($this->request->data); if ($this->Upload->validates()) { //http://milesj.me/code/cakephp/uploader $this->Uploader = new Uploader(array('tempDir' => TMP, 'baseDir' => WWW_ROOT, 'uploadDir' => 'files/uploads/' . $userFolder . '/', 'maxNameLength' => 200)); if ($data = $this->Uploader->upload('fileName')) { // Upload successful, do whatever //debug($data); //Add pertinent data to the array $this->request->data['Upload'] = $data; $this->request->data['Upload']['active'] = 1; //Disable until the user pays $this->request->data['Upload']['user_id'] = $this->Upload->User->getLastInsertID(); //$this->request->data['Upload']['caption'] = $this->request->data['Upload']['custom_name']; $this->Upload->create(); if ($this->Upload->save($this->request->data)) { //Set the upload id $this->request->data['Upload']['id'] = $this->Upload->getLastInsertID(); } else { $this->Session->setFlash(__('Bummer :( Your file could NOT be uploaded.')); $this->log('The file could not be uploaded.', 'upload_debug'); Debugger::log($data); } } } } $works = $this->Upload->Work->find('list'); $this->set(compact('works')); }
static function openChartWithId($_cid) { require_once '../config.php'; require_once 'charts/PieChart.php'; require_once 'charts/Column.php'; global $db; $sql = "select * from colfusion_charts where id = " . $_cid; $rst = $db->get_result($sql); $obj = $rst[0]; $datainfo = str_replace('\\"', '"', $obj->datainfo); include_once 'Debug/Debugger.php'; Debugger::var_dump_value('cid', $_cid, null); if ($obj->type == "pie") { return new PieChart($_cid, $obj->name, $obj->canvas, $obj->type, $obj->left, $obj->top, $obj->depth, $obj->height, $obj->width, $obj->datainfo, $obj->note); } if ($obj->type == "column") { return new ColumnChart($_cid, $obj->name, $obj->canvas, $obj->type, $obj->left, $obj->top, $obj->depth, $obj->height, $obj->width, $obj->datainfo, $obj->note); } if ($_type == "table") { return new TableChart($_cid, $obj->name, $obj->canvas, $obj->type, $obj->left, $obj->top, $obj->depth, $obj->height, $obj->width, $obj->datainfo, $obj->note); } if ($_type == "combo") { return new ComboChart($_cid, $obj->name, $obj->canvas, $obj->type, $obj->left, $obj->top, $obj->depth, $obj->height, $obj->width, $obj->datainfo, $obj->note); } if ($_type == "map") { return new MapChart($_cid, $obj->name, $obj->canvas, $obj->type, $obj->left, $obj->top, $obj->depth, $obj->height, $obj->width, $obj->datainfo, $obj->note); } if ($_type == "motion") { return new MotionChart($_cid, $obj->name, $obj->canvas, $obj->type, $obj->left, $obj->top, $obj->depth, $obj->height, $obj->width, $obj->datainfo, $obj->note); } }
public function getDebugger(array $config = []) { if (null === $this->debugger) { $this->debugger = Debugger::get(get_class($this), $config); } return $this->debugger; }
public function main() { $aUser = $this->User->find('all'); foreach ($aUser as $user) { $currTime = time(); $lastTime = strtotime(Hash::get($user, 'User.last_update')); //TODO дата с нынешней до last_update //если last_update давнее 12 часов, то брать последние 12 часов $id = $user['User']['id']; $date1 = $lastTime > $currTime - 43200 ? date("Y-m-d H:i:s", $lastTime) : date("Y-m-d H:00:00", $currTime - 43200); $date2 = date("Y-m-d H:i:s"); $data = $this->User->getTimeline($id, $date1, $date2, 0, true); //$this->set('data', $data); //$this->set('timeFrom', strtotime($date1)); //$this->set('timeTo', strtotime($date2)); if (count($data['events'])) { Debugger::dump($user['User']['id'] . ' ' . $user['User']['full_name'] . ' from: ' . $date1 . ' to: ' . $date2); //Debugger::dump($data['events']); /* $Email = new CakeEmail('postmark'); $Email->template('updates_mailer', 'mail')->viewVars( array('data' => $data, 'timeFrom' => strtotime($date1), 'timeTo' => strtotime($date2), 'userID' => $user['User']['id'])) ->to(Hash::get($user, 'User.username')) ->subject('Last updates on Konstruktor.com') ->send(); */ } } }
public function actionCallback($oauth_token) { try { $login_secret = $this->getSession('oauth')->login_secret; if (!$oauth_token) { echo "Error! There is no OAuth token!"; exit; } if (!$login_secret) { echo "Error! There is no OAuth secret!"; exit; } $this->oauth->enableDebug(); $this->oauth->setToken($oauth_token, $login_secret); $access_token_info = $this->oauth->getAccessToken(self::ACCESS_TOKEN_URL); $this->getSession('oauth')->login_secret = false; $this->getSession('oauth')->token = $access_token_info['oauth_token']; $this->getSession('oauth')->secret = $access_token_info['oauth_token_secret']; $this->getUserDetailsAndLoginUser(); } catch (OAuthException $E) { Debugger::log($E); //zalogujeme for sichr echo "OAuth login failed. Please, contact administrator."; $this->terminate(); } }
/** * Detect available adapter * @return string */ private static function detect() { static $autoDetected = null; if ($autoDetected) { return $autoDetected; } if (!Debugger::isCachesEnabled()) { Debugger::addLine('Caching disabled by Debug Mode settings'); return self::INST_NONE; } if (Cache\APCu::isAvailable()) { Debugger::addLine('Auto-detected cache type: APCu'); return $autoDetected = self::INST_APCU; } if (Cache\XCache::isAvailable()) { Debugger::addLine('Auto-detected cache type: XCache'); return $autoDetected = self::INST_XCACHE; } elseif (Cache\MemCached::isAvailable()) { Debugger::addLine('Auto-detected cache type: MemCached'); return $autoDetected = self::INST_MEMCACHED; } elseif (Cache\MemCache::isAvailable()) { Debugger::addLine('Auto-detected cache type: Memcache'); return $autoDetected = self::INST_MEMCACHE; // } elseif (Cache\SharedMemory::isAvailable()) { // Debugger::getInstance()->addLine('Auto-detected cache type: Shared Memory'); // return $autoDetected = self::INST_SHAREDMEM; } Debugger::addLine('No cache detected'); return $autoDetected = self::INST_NONE; }
/** * Sets a timer point before rendering a file. * * @param string $viewFile The view being rendered */ public function beforeRenderFile($viewFile) { if ($this->_renderComplete) { return; } DebugTimer::start('render_' . basename($viewFile), __d('debug_kit', 'Rendering %s', Debugger::trimPath($viewFile))); }
function activate() { $setup = Config::get('RPC'); $class = URL::getPathPart($setup['class']); $method = URL::getPathPart($setup['method']); list($action, $type) = explode('.', URL::getPathPart($setup['action']), 2); $path = $setup["path"] . "/" . $class . "/" . ucwords($method) . ucwords($action) . "Controller"; if (file_exists(Loader::getPath("controller", $path))) { Debugger::log("CONTROLLER: <span style=\"color: #990000\">" . ucwords($method) . ucwords($action) . "Controller</span>"); $controller = Loader::loadNew("controller", $path); $controller->activate(); if (is_callable(array($controller, $type))) { echo $controller->{$type}(); } return; } $controller_class = ucwords($class) . ucwords($method) . ucwords($action) . "Controller"; Debugger::log("CONTROLLER: <span style=\"color: #990000\">{$controller_class}</span>"); if (file_exists(Loader::getPath("controller", "{$setup['path']}/{$controller_class}"))) { $controller = Loader::loadNew("controller", "{$setup['path']}/{$controller_class}"); $controller->activate(); } else { Loader::load("utility", "Server"); $ip = Server::getIP(); $self = Server::getSelf(); Debugger::log("Possible RPC Injection: RPC call to non-existent controller at path {$setup["path"]}/{$controller_class} {$ip} {$self}"); error_log("Possible RPC Injection: RPC call to non-existent controller at path {$setup['path']}/{$controller_class} {$ip} {$self}"); } }
/** * * singletone pattern * @param array * @return Debugger instance */ public static function getInstance(array $params = array()) { if (!self::$instance) { self::$instance = new self($params); } return self::$instance; }
public function Resize($image, $newWidth, $targetName) { if (!file_exists(PUBLIC_ROOT . $image)) { $image = '/assets/images/not-found.gif'; } $imgInfo = getimagesize(PUBLIC_ROOT . $image); $oldWidth = $imgInfo[0]; $oldHeight = $imgInfo[1]; $changeRatio = $oldWidth / $newWidth; $newHeight = round($oldHeight / $changeRatio); $newImage = imagecreatetruecolor($newWidth, $newHeight); $source = $this->load(PUBLIC_ROOT . $image); if ($this->imageType == IMAGETYPE_PNG) { imagealphablending($newImage, false); imagesavealpha($newImage, true); $transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127); imagefilledrectangle($newImage, 0, 0, $newWidth, $newHeight, $transparent); } imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight); header('Content-Type: image/jpeg'); imagejpeg($newImage, $targetName, 100); Debugger::debug($targetName, 'TARGET'); //$this->save($targetName); $this->image = $newImage; imagedestroy($newImage); }
/** * Debugger::dump shortcut. */ function dump($var) { foreach (func_get_args() as $arg) { Debugger::dump($arg); } return $var; }
public static function GetInstance() { if (self::$instance == null) { self::$instance = new Debugger(); } return self::$instance; }
/** * Start an benchmarking timer. * * @param string $name The name of the timer to start. * @param string $message A message for your timer * @return bool Always true */ public static function start($name = null, $message = null) { $start = microtime(true); if (!$name) { $named = false; $calledFrom = debug_backtrace(); $name = Debugger::trimpath($calledFrom[0]['file']) . ' line ' . $calledFrom[0]['line']; } else { $named = true; } if (!$message) { $message = $name; } $_name = $name; $i = 1; while (isset(self::$_timers[$name])) { $i++; $name = $_name . ' #' . $i; } if ($i > 1) { $message .= ' #' . $i; } self::$_timers[$name] = array('start' => $start, 'message' => $message, 'named' => $named); return true; }
function __construct($number, $error, $query = null) { $this->number = $number; $this->error = $error; $this->query = $query; Debugger::error(new Exception((string) $this)); }
static function getInstance() { if (self::$instance == NULL) { self::$instance = new Debugger(); } return self::$instance; }
public static function getHtml($message, $file, $line, $context = null) { $params = Router::getRequest(); $trace = Debugger::trace(array('start' => 2, 'format' => 'base')); $session = isset($_SESSION) ? $_SESSION : array(); $msg = array('<p><strong>', $message, '</strong></p>', '<p>', $file . '(' . $line . ')', '</p>', '', '<h2>', 'Backtrace:', '</h2>', '', '<pre>', trim($trace), '</pre>', '', '<h2>', 'Request:', '</h2>', '', '<h3>URL</h3>', self::getUrl(), '<h3>Client IP</h3>', self::getClientIp(), '<h3>Referer</h3>', env('HTTP_REFERER'), '<h3>Parameters</h3>', self::dumper($params), '<h3>Cake root</h3>', APP, '', '<h2>', 'Environment:', '</h2>', '', self::dumper($_SERVER), '', '<h2>', 'Session:', '</h2>', '', self::dumper($session), '', '<h2>', 'Cookie:', '</h2>', '', self::dumper($_COOKIE), '', '<h2>', 'Context:', '</h2>', '', self::dumper($context), ''); return join("\n", $msg); }
function d($msg) { if (class_exists('Debugger') && $this->config->debug) { Debugger::d('Application', $msg); } else { die('No debugger attached'); } }
public static function instance() { if (!isset(self::$staticObj)) { $className = __CLASS__; self::$staticObj = new $className(); } return self::$staticObj; }
public function __construct($message = null, $code = 0, Exception $previous = null) { if (Configure::read('ModularAuth.debug_trace')) { $trace = "\n" . Debugger::trace(array('start' => 1)); var_dump($trace); } parent::__construct($message, $code, $previous); }
public static function setDebugger($name = 'default') { self::$debuggerName = $name; $args = func_get_args(); array_shift($args); $className = 'Debugger' . $name; self::$debuggerInstance = new $className($args[0], $args[1]); }
public function addServer($host = 'localhost', $port = 11211, $timeout = 1) { Debugger::tryError(); $this->memcache->addServer($host, $port, TRUE, 1, $timeout); if (Debugger::catchError($e)) { throw new InvalidStateException('Memcache::addServer(): ' . $e->getMessage(), 0, $e); } }
public function processAPI() { Debugger::debug('API_' . ucwords($this->endpoint)); if (class_exists('API_' . ucwords($this->endpoint))) { return $this->_response($this->getResult()); } return $this->_response(array('error' => "Invalid Endpoint: {$this->endpoint}"), 404); }
public static function error_handling_dev($err_no, $err_str, $err_file, $err_line, $err_context) { $exception = new ErrorException($err_str, 0, $err_no, $err_file, $err_line); Debugger::error($exception); $ErrorHandler = new ErrorHandler($exception); $ErrorHandler->ProcessError(); return; }
private static function connect() { try { self::$db = new \PDO('mysql:host=' . self::$dbHost . ';dbname=' . self::$dbName . ';charset=utf8', self::$dbUser, self::$dbPass); self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { Debugger::debug('error'); Errors::handle($e, 'sqlerr'); } }
public function testIsPowerOfTwo() { $powersOfTwo = [1, 2, 4, 8, 16, 32, 64]; for ($i = 1; $i <= 64; $i++) { if (in_array($i, $powersOfTwo)) { $this->assertTrue(Debugger::isPowerOfTwo($i)); } else { $this->assertFalse(Debugger::isPowerOfTwo($i)); } } }
/** * Call registered handlers for an event * @param $event */ private static function start($event) { $handlers = self::$events[$event]; if (empty($handlers)) { return; } foreach ($handlers as $handler) { Debugger::addEventLine('Handler for ' . $event . ': ' . $handler['class'] . '->' . ($handler['method'] ? $handler['method'] : 'getInstance') . ' started'); call_user_func([$handler['class'], $handler['method']]); } }
function activate() { if (!Config::isLive() && file_exists($this->bypass)) { Debugger::log("<span style='color: #939393'>Follow {$this->type} Redirect to:</span> <br><a href='{$this->url}' style='color: white;'>{$this->url}</a> "); exit; } else { header("Location: {$this->url}", true, $this->type); exit; } return; }
/** * Overload _render to capture filenames and time actual rendering of each view file * * @param string $___viewFn Filename of the view * @param array $___dataForView Data to include in rendered view * @return string Rendered output * @access protected */ function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) { if (!isset($___dataForView['disableTimer'])) { DebugKitDebugger::startTimer('render_' . basename($___viewFn), sprintf(__d('debug_kit', 'Rendering %s', true), Debugger::trimPath($___viewFn))); } $out = parent::_render($___viewFn, $___dataForView, $loadHelpers, $cached); if (!isset($___dataForView['disableTimer'])) { DebugKitDebugger::stopTimer('render_' . basename($___viewFn)); } return $out; }