/** * @brief updates the cron row to show the process as complete * * When the cron run is done this method is called to mark the end of the * process, along with recording some stats on the system that can * later be used for analysys. * * @param int $tasksRan the number of events that did something * @param string $memAverage average memory usage for the run * @param string $loadAverage system load average for the run * @access public * * @return AppModel::save() */ public function end($tasksRan = 0, $memAverage = 0, $loadAverage = 0) { if (!$this->_currentProcess) { trigger_error(__('Cron not yet started'), E_USER_WARNING); return false; } $data = null; $memUsage = memoryUsage(false, false); $serverLoad = serverLoad(false); $serverLoad[0] = $serverLoad[0] >= 0 ? $serverLoad[0] : 0; $data['Cron'] = array('id' => $this->_currentProcess, 'end_time' => date('H:i:s'), 'end_mem' => $memUsage['current'], 'end_load' => $serverLoad[0], 'mem_ave' => $memAverage, 'load_ave' => $loadAverage, 'tasks_ran' => $tasksRan, 'done' => 1); unset($memUsage, $serverLoad); $this->_currentProcess = null; return $this->save($data); }
/** * Generates output for the Memory Usage Tab * * @version 1.0 * @since 1.0.0 * @author Dan Aldridge * * @param bool $output If True, The function will output the HTML * * @return array */ public function getMemoryUse($output = false) { if ($output !== true) { return false; } $output = null; $debug = memoryUsage('System: OUTPUT!'); $output .= '<table class="table table-bordered"><tr>'; $output .= sprintf('<th>%s</th>', 'Execution <br />Time'); $output .= sprintf('<th>%s</th>', 'File <br />Lines'); $output .= sprintf('<th>%s</th>', 'Messages <br />' . count($debug)); $output .= sprintf('<th>%s</th>', 'Memory <br />' . formatBytes(memory_get_usage())); $output .= '</tr><tr>'; $header = null; $memory = 0; $oldTime = 0; foreach ($debug as $row) { $info = explode(':', $row['info'], 2); if ($info[0] == 'OUTPUT!') { continue; } if ($header !== $info[0]) { $header = $info[0]; $output .= '</tr><tr><td colspan="11" style="height: 2px; padding: 0;"></td>'; } $mem = $row['memory_exec'] - $memory; $output .= '</tr><tr>'; $timeDiff = $row['time_exec'] - $oldTime; $output .= sprintf('<td width="10%%">%s</td>', $row['time_exec'] . ' <br />(' . (substr($timeDiff, 0, 1) == '-' ? '-' . $timeDiff : '+' . $timeDiff) . ')'); $output .= sprintf('<td width="20%%">%s <br />%s</td>', $row['file_exec'], $row['start_exec'] . ' - ' . $row['end_exec']); $output .= sprintf('<td width="">%s</td>', $info[1]); $output .= sprintf('<td width="15%%">%s</td>', substr($mem, 0, 1) == '-' ? '-' . formatBytes(-$mem) . '<br />Cleared' : formatBytes($mem) . '<br />Used'); $memory = $row['memory_exec']; $oldTime = $row['time_exec']; } $output .= '</tr></table>'; return array('count' => formatBytes(memory_get_usage()), 'content' => $output); }
$page = intval($_GET['p']); $photos_count = sizeof($pa->getAlbumPhotos()); $last_page = ceil($photos_count/AT_PA_PHOTOS_PER_PAGE); if (!$page || $page < 0) { $page = 1; } elseif ($page > $last_page){ $page = $last_page; } $count = (($page-1) * AT_PA_PHOTOS_PER_PAGE) + 1; $offset = ($page-1) * AT_PA_PHOTOS_PER_PAGE; //get details $photos = $pa->getAlbumPhotos($offset); $comments = $pa->getComments($id, false); //TODO: Can improve performance by adding this to a session variable $memory_usage = memoryUsage($_SESSION['member_id']); include (AT_INCLUDE_PATH.'header.inc.php'); $savant->assign('album_info', $info); $savant->assign('photos', $photos); $savant->assign('comments', $comments); $savant->assign('page', $page); $savant->assign('num_rows', $photos_count); $savant->assign('memory_usage', $memory_usage/(1024*1024)); //mb $savant->assign('allowable_memory_usage', $_config['pa_max_memory_per_member']); //mb $savant->assign('action_permission', $pa->checkAlbumPriv($_SESSION['member_id'])); $savant->display('photos/pa_profile_albums.tmpl.php'); include (AT_INCLUDE_PATH.'footer.inc.php'); ?>
"<td><table width=100%>$top_by_tours</table></td></tr>"; $cap_content .= "</tr></table>"; $filter_content = "<table class=mt width=100%>". "<tr align=center height=30>". "<th>Выбрать лигу:</th>"; for ($i = 0; $i < count($leagues); $i++) { $filter_content .= "<th style='background:".$lcolors[$i]."'>". "<a class=ab href='#".$leagues[$i]."'>".$leagues[$i]."</a></th>"; } $filter_content .= "<th style='text-align:right;padding:3'>Последнее обновление: <b>".intToDate($max_date)."</b></th>". "</tr>". "</table>"; $elapsed_time = number_format(microtime(true) - $start_time, 3); $m = memoryUsage($_m); $_m = $_m > 0 ? " (memory before the script run: <b>$start_memory</b>)" : ""; $end_content .= '<table>'. '<tr><td colspan=2 align=center>Данные собраны с сайта: <a href="http://or.rttf.ru">http://or.rttf.ru</a></td></tr>'. '<tr>'. //'<td class=p1 valign=bottom>Memory usage: <b>'.$m.'</b>'.$_m.' ('.$elapsed_time.' s)</td>'. //'<td colspan=3 align=center valign=bottom> © <a target=_blank class=ab href="http://www.rttf.ru/user/27981">Гарус Игорь</a> (aabzac)</td>'. '</tr></table>'; echo '<table class=frame width=70%>'. "<tr><td>$filter_content</td></tr>". "<tr><td>$cap_content</td></tr>". "<tr align=center><td>$players_content</td></tr>". "<tr align=center><td>$end_content</td></tr>". '</table>';
public function showFooter() { if (!$this->getOptions('completed')) { return; } $objTPL = self::getTPL(); // run a check on simple $simple = $this->getOptions('mode') ? true : false; // see if we are gonna get the simple one or the full blown one $footer = $simple ? 'simple_footer.tpl' : 'site_footer.tpl'; $objTPL->set_filenames(array('siteFooter' => self::$THEME_ROOT . $footer)); $this->buildBlocks(); cmsDEBUG ? memoryUsage('System: Finished Loading.') : ''; if (defined('cmsDEBUG') && cmsDEBUG === true && (LOCALHOST || Core_Classes_User::$IS_ADMIN)) { $objDebug = Core_Classes_coreObj::getDebug(); $objTPL->assign_block_vars('debug', array('DEBUG' => $objDebug->output())); } $objTPL->parse('siteFooter'); }
/** * @brief output some stats for the cron that just ran */ public function stats() { if ($this->verbose) { $this->log('Below are the stats for the run'); $this->hr(); } $memoryUsage = $totalMemoryUsed = null; $memoryUsage = memoryUsage(false); $totalMemoryUsed = round(substr($memoryUsage['current'], 0, -3) - substr($this->memoryUsage['start']['current'], 0, -3), 3); $this->log(sprintf('Total time taken :: %s sec', $this->elapsedTime())); $this->log(sprintf('Load max :: %s', max($this->_loadLog))); $this->log(sprintf('Load average :: %s', $this->averageLoad())); $this->log(sprintf('Memory max :: %s', $memoryUsage['max'])); $this->log(sprintf('Memory current :: %s', $memoryUsage['current'])); $this->log(sprintf('Memory average :: %s mb', $this->averageMemoryUsage())); $this->log(sprintf('Memory used :: %s mb', $totalMemoryUsed)); }
// AUTOLOADER, I Choose You! // directories to use for the autoloading, these get glob'd over after // $dirs = Core_Classes_coreObj::addClassDirs(array( // 'classes' => cmsROOT.'core/classes/*.php', // 'libs' => cmsROOT.'core/libs/*/class.*.php', // 'drivers' => cmsROOT.'core/drivers/driver.*.php', // 'admin_panels' => cmsROOT.'modules/*/admin.*.php', // 'modules' => cmsROOT.'modules/*/class.*.php', // 'module_overrides' => cmsROOT.'themes/*/override/*/*.php', // )); spl_autoload_extensions('.php'); spl_autoload_register(array('Core_Classes_coreObj', 'loadClass')); // echo dump($dirs, 'Loading Classes From', 'orange');exit; $objCore = new Core_Classes_coreObj(); $objCore->addConfig($config); // Instance plugins so we can add hooks as early as possible. $objPlugin = Core_Classes_coreObj::getPlugins(); $objPlugin->hook('CMS_PRE_SETUP_COMPLETE'); $objCache = Core_Classes_coreObj::getCache(); $confCache = $objCache->load('config'); $objCore->addConfig($confCache); $objSession = Core_Classes_coreObj::getSession(); $objSession->trackerInit(); $objDebug = Core_Classes_coreObj::getDebug(); $objRoute = Core_Classes_coreObj::getRoute(); $objRoute->modifyGET(); if (is_object($objDebug)) { set_error_handler(array($objDebug, 'errorHandler')); } cmsDEBUG ? memoryUsage('Core: Loaded..') : ''; $objPlugin->hook('CMS_SETUP_COMPLETE');
{ echo "Hi I am a static method, and this is the parameter passed to me: {$variable}!"; } } // draw $tpl = new Tpl(); $tpl->assign($var); echo $tpl->drawString($string); // -- end //------------------------------------------------------------- // // BENCHMARK/DEBUG FUNCTIONS // //------------------------------------------------------------- echo "<br>---------<br>"; echo memoryUsage(); echo "<br>"; echo timer(); /** * Useful for debug, print the variable $mixed and die */ function dump($mixed, $exit = 1) { echo "<pre>dump \n---------------------- \n\n" . print_r($mixed, true) . "\n----------------------<pre>"; if ($exit) { exit; } } /** * Save the memory used at this point */
/** * Check if the photo is supported, including extension check, file size check * and library support checks. * @param string location of the file. * @return $_FILE[] on successful, null on failure. */ function checkPhoto($file) { global $stripslashes; global $msg, $_config; $msg = new AjaxMessage(); // check if GD is installed if (!extension_loaded('gd')) { $msg->printInfos('FEATURE_NOT_AVAILABLE'); return false; } // check if folder exists, if not, create it if (!is_dir(AT_PA_CONTENT_DIR)) { mkdir(AT_PA_CONTENT_DIR); } //check GD support $gd_info = gd_info(); $supported_images = array(); if ($gd_info['GIF Create Support']) { $supported_images[] = 'gif'; } if ($gd_info['JPG Support'] || $gd_info['JPEG Support']) { $supported_images[] = 'jpg'; } if ($gd_info['PNG Support']) { $supported_images[] = 'png'; } if (!$supported_images) { $msg->printInfos('FEATURE_NOT_AVAILABLE'); return false; } // check if this is a supported file type $filename = $stripslashes($file['name']); $path_parts = pathinfo($filename); $extension = strtolower($path_parts['extension']); $image_attributes = getimagesize($file['tmp_name']); //check Extension if ($extension == 'jpeg') { $extension = 'jpg'; } if (!in_array($extension, $supported_images)) { $msg->addError(array('FILE_ILLEGAL', $extension)); return false; } else { if ($image_attributes[2] > IMAGETYPE_PNG) { $msg->addError(array('FILE_ILLEGAL', $extension)); return false; } } // make sure under max file size $allowed_usage = $_config['pa_max_memory_per_member'] * 1024 * 1024; //mb if (memoryUsage($_SESSION['member_id']) > $allowed_usage) { $msg->addError('PA_EXCEEDED_MAX_USAGE'); return false; } //check filename $file['name'] = str_replace(array('\'', '"', ' ', '|', '\\', '/', '<', '>', ':'), '_', $file['name']); $file['name'] = preg_replace("/[^A-Za-z0-9._\\-]/", '', $file['name']); return $file; }
<? $_m = memory_get_usage(); $start_memory = memoryUsage(-1); $start_time = microtime(true); include '../link.php'; include '../hwm/counter/add.php'; get_ip(); header('Content-Type: text/html; charset=utf-8'); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'; echo '<html><head>'; echo '<link rel="stylesheet" type="text/css" href="css/main.css">'; echo '<script type="text/javascript" src="js/main.js"></script>'; echo "<title>Кубок</title>"; echo '<link rel="stylesheet" href="../../jquery-ui-1.11.4/jquery-ui.css">'; echo '<style>.dp-highlight .ui-state-default {background: #484;color: #FFF;}</style>'; echo '<script src="../../jquery-ui-1.11.4/external/jquery/jquery.js"></script>'; echo '<script src="../../jquery-ui-1.11.4/jquery-ui.js"></script>'; echo '</head>'; echo '<body><center>'; $n_groups = 2; $commands1 = array("Команда1", "Команда2", "Команда3", "Команда4"); $commands2 = array("Команда5", "Команда6", "Команда7", "Команда8"); $players1 = array( $commands1[0] => array('Игрок1-1', 'Игрок1-2', 'Игрок1-3', 'Игрок1-4', 'Игрок1-5'), $commands1[1] => array('Игрок2-1', 'Игрок2-2', 'Игрок2-3', 'Игрок2-4', 'Игрок2-5'), $commands1[2] => array('Игрок3-1', 'Игрок3-2', 'Игрок3-3', 'Игрок3-4', 'Игрок3-5'), $commands1[3] => array('Игрок4-1', 'Игрок4-2', 'Игрок4-3', 'Игрок4-4', 'Игрок4-5'), ); $players2 = array(
/** * Invokes the action of a route * * @version 1.0 * @since 1.0.0 * @author Daniel Noel-Davies & Dan Aldridge * * @return bool */ public function invokeRoute() { $route = $this->getVar('route'); if (is_empty($route)) { $this->throwHTTP(404); return; } cmsDEBUG ? memoryUsage('Route: Executing Route ' . dump($route)) : ''; $objUser = Core_Classes_coreObj::getUser(); // Check if the route is a redirection if (!is_empty($route['redirect'])) { // TODO: Add Internal Redirections (Internal, meaning no 301, just different internal processing) $this->throwHTTP(301, $route['redirect']); return true; } // We assume the invoke is a module call, Let's go! $module = $route['arguments']['module']; $method = $route['arguments']['method']; // Check the class and subsequent method are callable, else trigger an error if (class_exists($module) === false || is_callable(array($module, $method)) === false) { trigger_error('The module or method you are trying to call, dosen\'t exist.'); $a = array('module' => $module, 'method' => $method); echo dump($a, 'You are trying to call..'); return false; } // test for override within the directory $_module = str_replace('Modules_', '', $module); $path = cmsROOT . 'themes/%1$s/override/modules/%2$s/%3$s/class.%3$s.php'; if (is_readable(sprintf($path, $objUser->grab('theme'), $_module, $method)) === true) { $overrideClass = 'Override_Modules_' . $_module . '_' . $method; $getMethod = new ReflectionMethod($overrideClass, $method); // test to see if its callable, & declared in the right bloody class >.< if (is_callable(array($overrideClass, $method)) && $getMethod->getDeclaringClass()->name === $overrideClass) { $module = $overrideClass; } } // Retrieve the info we need about the class and method $refMethod = new ReflectionMethod($module, $method); $params = $refMethod->getParameters(); $args = array(); // Loop through the parameters the method asks for, and match them up with our arguments foreach ($params as $k => $name) { $var = $name->getName(); // check if the var they asked for is in the params if (!isset($route['arguments'][$var])) { $args[$var] = null; continue; } // and then check if we have to throw the var at them as a reference if ($name->isPassedByReference()) { $args[$var] =& $route['arguments'][$var]; } else { $args[$var] = $route['arguments'][$var]; } } // GO! $Module!, $Module used $Method($args)... It was super effective! ob_start(); $objModule = new $module(); $objModule->setVars(array('_method' => $method, '_module' => $module, '_params' => $route['arguments'])); $refMethod->invokeArgs($objModule, $args); $objPage = Core_Classes_coreObj::getPage(); $objPage->addMeta(array('name' => 'module', 'content' => $module)); $objPage->addMeta(array('name' => 'method', 'content' => $method)); $objPage->setVar('contents', ob_get_clean()); return $objModule; }
/** * Sets the upload directory to a specific location, assuming it's writable * * @version 1.0 * @since 1.0.0 * @author Richard Clifford * * @param string $directory * @param bool $create * * @return boolean */ public function setDirectory($directory = '', $create = false) { $objPlugins = Core_Classes_coreObj::getPlugins(); if (trim($directory) === '') { cmsDEBUG ? memoryUsage('Upload: Using default folder') : ''; $this->setVar('directory', sprintf('%sassets/uploads/all', cmsROOT)); } else { // If create is set then create a new folder if ($create === true && !file_exists($directory)) { $this->_mkDir($directory); } // Checks if the given directory is writable if (!file_exists($directory) || file_exists($directory) && !is_writable($directory)) { cmsDEBUG ? memoryUsage('Upload: Destination folder was not writable') : ''; trigger_error(sprintf('The destination folder was not writable, please chmod it to 0775 : %s', $directory)); return false; } else { cmsDEBUG ? memoryUsage('Upload: Setting upload directory') : ''; $this->setVar('directory', $directory); return true; } } return false; }
<?php function memoryUsage($usage, $base_memory_usage) { printf("Bytes diff: %d\n", $usage - $base_memory_usage); } $mem = memory_get_usage(); $mem = memory_get_usage(); memoryUsage(memory_get_usage(), $mem); $a = array(0, &$a); $b =& $a; unset($a); //unset($b); xdebug_debug_zval('a'); xdebug_debug_zval('b'); //gc_collect_cycles(); memoryUsage(memory_get_usage(), $mem);
<?php function memoryUsage($usage, $base_memory_usage) { printf("Bytes diff: %d\n", $usage - $base_memory_usage); } function someBigValue() { return str_repeat('SOME BIG STRING', 4); } echo "String memory usage test.\n\n"; $base_memory_usage = memory_get_usage(); $base_memory_usage = memory_get_usage(); $a = someBigValue(); $b = $a; //$b = strval($b); echo "String value setted"; memoryUsage(memory_get_usage(), $base_memory_usage); unset($a, $b); echo "Unset"; memoryUsage(memory_get_usage(), $base_memory_usage);
public function __construct($request = null, $response = null) { $this->serverLoad = serverLoad(false); $this->memoryUsage = memoryUsage(false, false); parent::__construct($request, $response); }
/** * 总体耗费描述 * * @return string */ function theUsage() { return "Memory used:" . memoryUsage() . " mb, Progress times:" . queryTime() . " s."; }