/** * Clean the cache * * @return boolean TRUE, simulating success */ public function cleanCache() { if (function_exists('profiler_log')) { profiler_log('CACHE', 'APC Write OK: ' . $type . '/' . $name . '/' . $ID); } return TRUE; }
/** * Call any method inside common module, else call $APP method * * @param type $name * @param array $arguments * @return type * @throws Exception */ public function __call($name, array $arguments) { if (method_exists($this->xtends, $name)) { return call_user_func_array(array($this->xtends, $name), $arguments); } if (method_exists(CI::$APP, $name)) { return call_user_func_array(array(CI::$APP, $name), $arguments); } if (method_exists($this, '_' . $name)) { $ID = md5(json_encode($arguments)); $methodName = '_' . $name; if (($result = $this->xdbcache->xcache->readCache('cache_methods', get_class($this) . '_' . $methodName, $ID)) !== FALSE) { if (function_exists('profiler_log')) { profiler_log('CACHE', "Cache Method GET: " . get_class($this) . "/" . $methodName); } } else { $result = call_user_func_array(array(&$this, $methodName), $arguments); $this->xdbcache->xcache->writeCache('cache_methods', get_class($this) . '_' . $methodName, $ID, $result); if (function_exists('profiler_log')) { profiler_log('CACHE', "Cache Method PUT: " . get_class($this) . "/" . $methodName); } } return $result; } throw new Exception('No such method: ' . $name); }
/** * Cache Save * * @param string Unique Key * @param mixed Data to store * @param int Length of time (in seconds) to cache the data * * @return boolean TRUE, Simulating success */ public function writeCache($type, $name, $ID, $output, $depID = "") { $originalID = $ID; //if (function_exists('profiler_log')) profiler_log('CACHE','Memcache Write init : '.$type.'/'.$name.'/'.$ID); $item_expiration = $this->getCacheItemExpiration($type, $name, $originalID); if (is_array($item_expiration)) { $item_properties = $item_expiration; $name .= '-' . $item_properties[0]; $item_expiration = $item_properties[1]; } if ($item_expiration == FALSE) { $item_expiration = $this->getCacheConfigItem('default', $type); if ($item_expiration == FALSE) { return FALSE; } } $this->getInstance()->set($type . '-' . $name . '-' . $ID, serialize($output), MEMCACHE_COMPRESSED, $item_expiration); if (function_exists('profiler_log')) { profiler_log('CACHE', 'Memcache Write OK: ' . $type . '/' . $name . '/' . $ID); } return TRUE; }
/** * Sets the given parameter into the debug bar Variables -> DEBUG VARS section * @param mixed $vars * @return void */ function debug_vars($vars) { $callerTrace = reset(debug_backtrace(0, 1)); profiler_log('DEBUG VARS', $callerTrace['file'] . ': ' . $callerTrace['line'], $vars); }
/** * Cache Save * * @param string Unique Key * @param mixed Data to store * @param int Length of time (in seconds) to cache the data * * @return boolean TRUE, Simulating success */ public function writeCache($type, $name, $ID, $output, $depID = "") { $originalID = $ID; if (isset($_POST) && count($_POST) > 0) { $ID = $ID . md5(serialize($_POST)); } self::logMessage('debug', "Writting file {$type} {$name} {$ID}"); $cache_path = $this->getCacheConfigItem('cache_path'); if (!is_dir($cache_path)) { @mkdir($cache_path, 0777, TRUE); } $cache_path = $cache_path . $type . '/' . $name . '/' . substr(md5($ID), 0, 2) . '/' . substr(md5($ID), 2, 2) . '/' . substr(md5($ID), 4, 2) . '/' . substr(md5($ID), 6, 2) . '/'; $item_expiration = $this->getCacheItemExpiration($type, $name, $originalID); if (is_array($item_expiration)) { $item_properties = $item_expiration; $name .= '-' . $item_properties[0]; $item_expiration = $item_properties[1]; } if ($item_expiration == FALSE) { $item_expiration = $this->getCacheConfigItem('default', $type); if ($item_expiration == FALSE) { return FALSE; } } if (!is_dir($cache_path)) { @mkdir($cache_path, 0777, TRUE); } if (!is_writable($cache_path)) { return FALSE; } $filepath = realpath($cache_path) . '/' . md5($ID); if (!($fp = fopen($filepath, 'wb'))) { self::logMessage('error', "Unable to write cache file: " . $filepath); return FALSE; } $expire = time() + $item_expiration; if (flock($fp, LOCK_EX)) { self::logMessage('debug', "Cache file writting: " . $filepath); if ($this->compress == TRUE) { fwrite($fp, $expire . 'TS--->' . gzdeflate(serialize($output))); } else { fwrite($fp, $expire . 'TS--->' . serialize($output)); } flock($fp, LOCK_UN); } else { self::logMessage('error', "Unable to secure a file lock for file at: " . $cache_path); return FALSE; } fclose($fp); @chmod($filepath, 0777); self::logMessage('debug', "Cache file written: " . $filepath); if (function_exists('profiler_log')) { profiler_log('CACHE', 'Cache File Write OK: ' . $type . '/' . $name . '/' . $ID); } return TRUE; }
function run() { if (IS_AJAX) { $position = 'relative'; } else { $position = 'absolute'; } profiler_log('SERVER', $_SERVER); profiler_log('COOKIES', $_COOKIE); profiler_log('CONFIG', CI::$APP->config->config); if ($this->CI->config->item("firePHP") != "firePHP") { // Load jQuery if not loaded $output = ''; $output = <<<WAK \t\t\t<script type="text/javascript"> \t\t\tif (window.require) require(['jquery'], function() {}); \t\t\telse if (!window.jQuery) { document.write(unescape('%3Cscript src=\\"http://code.jquery.com/jquery.min.js\\"%3E%3C/script%3E')) \t\t\t} \t\t\t</script> WAK; // Calculate relative path to document_root // $relativePath = str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace('\\','/',FCPATH)); // $output = "<script type=\"text/javascript\" src=\"".$relativePath."media/js/jquery-1.9.1.min.js\"></script>\n"; $i_currentDIV = rand(10, 99) . substr(md5($_SERVER["REQUEST_URI"]), 0, 6); $output .= "<div id='debugTrace" . $i_currentDIV . "X' style='position:{$position};top:0px;left:0px;width:10px;border:#FFFFEB solid 1px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#80000000,endColorstr=#10000000);background: rgba(135, 135, 135, 0.6);color:white;z-index:9999;'>"; $output .= "<a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler\").slideUp();jQuery(\".debugTraceProfiler2\").toggle();' style='text-decoration:none;font-size: 1em;'> <font color='white' size='1'>«</font> </a>"; $output .= "</div>"; $output .= "<div id='debugTrace" . $i_currentDIV . "' class='debugTraceProfiler2' style='position:{$position};top:0px;left:10px;width:100%;border:#FFFFEB solid 1px;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#80000000,endColorstr=#10000000);background: rgba(135, 135, 135, 0.6);color:red;z-index:9999;'>"; $output .= "<table align='center' border='0' width='98%'>"; $output .= "<tr>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_URI" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> URI </a></td>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_CTRL" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> Controler </a></td>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_MEM" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> Memory </a></td>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_BENCH" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> Benchmarks </a></td>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_VARS" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> Variables </a></td>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_SQL" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> SQL </a></td>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_CACHE" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> CACHE </a></td>"; $output .= "<td align='left' width='10%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#codeigniter_profiler_UTEST" . $i_currentDIV . "\").slideToggle();' style='text-decoration:none;font-size: 1em;color:#fff'> UNIT TEST </a></td>"; $output .= "<td align='right' width='30%'><a href='Javascript:;' onclick='jQuery(\".codeigniter_profiler" . $i_currentDIV . "\").slideUp();jQuery(\"#debugTrace" . $i_currentDIV . "\").hide();' style='text-decoration:none;font-size: 1em;color:#fff'>" . $this->CI->router->fetch_class() . "/" . $this->CI->router->fetch_method() . " <strong><<<</strong> </a></td>"; $output .= "<td align='right'> </td>"; $output .= "</tr>"; $output .= "<tr>"; $output .= "<td colspan='99' onclick='jQuery(\".codeigniter_profiler\").slideUp();'>"; $output .= "<div id='codeigniter_profiler_URI" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; $output .= $this->_compile_uri_string(); $output .= "</div>"; $output .= "<div id='codeigniter_profiler_CTRL" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; $output .= $this->_compile_controller_info(); $output .= $this->compile_traceLines('CLASS'); $output .= "</div>"; $output .= "<div id='codeigniter_profiler_MEM" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; $output .= $this->_compile_memory_usage(); $output .= "</div>"; $output .= "<div id='codeigniter_profiler_BENCH" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; $output .= $this->_compile_benchmarks(); $output .= "</div>"; $output .= "<div id='codeigniter_profiler_VARS" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; $output .= $this->_compile_get(); $output .= $this->_compile_post(); $output .= $this->compile_traceLines('DEBUG VARS'); $output .= $this->compile_traceLines('XVIEW'); $output .= $this->compile_traceLines('CONFIG'); $output .= $this->compile_traceLines('COOKIES'); $output .= $this->compile_traceLines('SERVER'); $output .= "</div>"; $output .= "<div id='codeigniter_profiler_SQL" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; // $output .= $this->compile_queries(); $output .= $this->compile_queries(); $output .= "</div>"; $output .= "<div id='codeigniter_profiler_CACHE" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; $output .= $this->compile_traceLines('CACHE'); $output .= "</div>"; $output .= "<div id='codeigniter_profiler_UTEST" . $i_currentDIV . "' class='codeigniter_profiler' style='position:relative;top:0px;padding:10px;width:90%;text-align:left;background-color:#fff;border:1px solid silver;z-index:9999;display:none;color:silver;'>"; $output .= $this->compile_unittests(); $output .= "</div>"; $output .= "</td>"; $output .= "</tr>"; $output .= "</table>"; $output .= "</div>"; return $output; } else { $this->firePHP(); } }
/** * Cache Save * * @param string Unique Key * @param mixed Data to store * @param int Length of time (in seconds) to cache the data * * @return boolean TRUE, Simulating success */ public function writeCache($type, $name, $ID, $output, $depID = "") { $originalID = $ID; //if (function_exists('profiler_log')) profiler_log('CACHE','Memcache Write init : '.$type.'/'.$name.'/'.$ID); $item_expiration = $this->getCacheItemExpiration($type, $name, $originalID); if (is_array($item_expiration)) { $item_properties = $item_expiration; $name .= '-' . $item_properties[0]; $item_expiration = $item_properties[1]; } if ($item_expiration == FALSE) { $item_expiration = $this->getCacheConfigItem('default', $type); if ($item_expiration == FALSE) { return FALSE; } } $expire = time() + $item_expiration; $this->getInstance()->update(array('ID' => $type . '-' . $name . '-' . $ID), array('ID' => $type . '-' . $name . '-' . $ID, 'insert' => time(), 'expires' => $expire, 'content' => serialize($output)), array("upsert" => true)); if (function_exists('profiler_log')) { profiler_log('CACHE', 'MongoDB Write OK: ' . $type . '/' . $name . '/' . $ID); } return TRUE; }