function check_php_upload_max_filesize() { $required = 2 * 1024 * 1024; $recommended = 16 * 1024 * 1024; $current = ini_get('upload_max_filesize'); if (str2mem($current) >= $recommended) { $req = 2; } else { if (str2mem($current) >= $required) { $req = 1; } else { $req = 0; } } $result = array('name' => S_PHP_UPLOAD_MAX_FILESIZE, 'current' => $current, 'required' => mem2str($required), 'recommended' => mem2str($recommended), 'result' => $req, 'error' => mem2str($required) . SPACE . S_IS_MINIMAL_FOR_PHP_ULOAD_FILESIZE_SMALL); return $result; }
/** * Checks for minimum PHP upload max filesize. * * @return array */ public function checkPhpUploadMaxFilesize() { $current = ini_get('upload_max_filesize'); return array('name' => _('PHP option upload_max_filesize'), 'current' => $current, 'required' => mem2str(self::MIN_PHP_UPLOAD_MAX_FILESIZE), 'result' => str2mem($current) >= self::MIN_PHP_UPLOAD_MAX_FILESIZE ? self::CHECK_OK : self::CHECK_FATAL, 'error' => _s('Minimum required PHP upload filesize is %s (configuration option "upload_max_filesize").', mem2str(self::MIN_PHP_UPLOAD_MAX_FILESIZE))); }
function stage2() { $final_result = true; $table = new CTable(null, 'requirements'); $table->setAlign('center'); /* Check PHP version */ $table->addRow($this->get_test_result($final_result, 'PHP version: ', phpversion(), version_compare(phpversion(), '4.3.0', '>='), 'Minimal version of PHP is 4.3.0')); $memory_limit = str2mem(ini_get('memory_limit')); $table->addRow($this->get_test_result($final_result, 'PHP Memory limit:', function_exists('memory_get_usage') ? mem2str($memory_limit) : 'unlimited', $memory_limit >= 8 * 1024 * 1024 || !function_exists('memory_get_usage'), '8M is a minimal PHP memory limitation')); $memory_limit = str2mem(ini_get('post_max_size')); $table->addRow($this->get_test_result($final_result, 'PHP post max size:', mem2str($memory_limit), $memory_limit >= 8 * 1024 * 1024, '8M is minimum size of PHP post')); $table->addRow($this->get_test_result($final_result, 'PHP max execution time:', ini_get('max_execution_time') . ' sec', ini_get('max_execution_time') >= 300, '300 sec is a maximal limitation on execution of PHP scripts')); /* Check supporteds databases */ global $ZBX_CONFIG; $table->addRow($this->get_test_result($final_result, 'PHP Databases support: ', new CScript(implode(SBR, $ZBX_CONFIG['allowed_db'])), !isset($ZBX_CONFIG['allowed_db']['no']), 'Required any databases support [MySQL or PostgreSQL or Oracle]')); /* Check BC math */ $bcmath_fnc_exist = function_exists('bcadd') && function_exists('bccomp') && function_exists('bcdiv') && function_exists('bcmod') && function_exists('bcmul') && function_exists('bcpow') && function_exists('bcscale') && function_exists('bcsqrt') && function_exists('bcsub'); $table->addRow($this->get_test_result($final_result, 'PHP BC math support', $bcmath_fnc_exist ? 'yes' : 'no', $bcmath_fnc_exist, 'Required bcmath module [configured PHP with --enable-bcmath]')); /* Check mb-strings $mbstrings_fnc_exist = mbstrings_available(); $table->addRow( $this->get_test_result( $final_result, 'PHP MB String support', $mbstrings_fnc_exist ? 'yes' : 'no', $mbstrings_fnc_exist, 'Required Multibyte String module [configured PHP with --enable-mbstring]')); //*/ /* Check GD existence */ $gd_version = S_NO; if (is_callable('gd_info')) { $gd_info = gd_info(); $gd_version = $gd_info['GD Version']; } $table->addRow($this->get_test_result($final_result, 'GD Version:', $gd_version, $gd_version != S_NO, 'The GD extension isn\'t loaded.')); /* Check supported image formats */ $img_formats = array(); if (isset($gd_info)) { //if($gd_info['JPG Support']) array_push($img_formats, 'JPEG'); if ($gd_info['PNG Support']) { array_push($img_formats, 'PNG'); } } if (count($img_formats) == 0) { $img_formats = array(S_NO); $no_img_formats = true; } $table->addRow($this->get_test_result($final_result, 'Image formats:', $img_formats, !isset($no_img_formats), 'Required images genetarion support [PNG]')); if (version_compare(phpversion(), '5.1.0RC1', '>=')) { $tmezone = ini_get('date.timezone'); $table->addRow($this->get_test_result($final_result, 'PHP Timezone:', empty($tmezone) ? 'n/a' : $tmezone, !empty($tmezone), 'Timezone for PHP is not set. Please set "date.timezone" option in php.ini.')); unset($tmezone); } if (!$final_result) { $this->DISABLE_NEXT_BUTTON = true; $this->addVar('trouble', true); $final_result = array(new CSpan(S_FAIL, 'fail'), BR(), BR(), 'Please correct all issuse and press "Retry" button', BR(), BR(), new CButton('retry', S_RETRY)); } else { $this->DISABLE_NEXT_BUTTON = false; $final_result = new CSpan(S_OK, 'ok'); } return array($table, BR(), $final_result); }
/** * Output profiling data. */ public function show() { global $DB; $debug_str = '<a name="debug"></a>'; $debug_str .= '******************** ' . _('Script profiler') . ' ********************' . '<br>'; $totalScriptTime = $this->stopTime - $this->startTime; $totalTimeStr = _s('Total time: %s', round($totalScriptTime, 6)); if ($totalTimeStr > $this->slowScriptTime) { $totalTimeStr = '<b>' . $totalTimeStr . '</b>'; } $debug_str .= $totalTimeStr . '<br>'; $sqlTotalTimeStr = _s('Total SQL time: %s', $this->sqlTotalTime); if ($sqlTotalTimeStr > $this->slowTotalSqlTime) { $sqlTotalTimeStr = '<b>' . $sqlTotalTimeStr . '</b>'; } $debug_str .= $sqlTotalTimeStr . '<br>'; if (isset($DB) && isset($DB['SELECT_COUNT'])) { $debug_str .= _s('SQL count: %s (selects: %s | executes: %s)', count($this->sqlQueryLog), $DB['SELECT_COUNT'], $DB['EXECUTE_COUNT']) . '<br>'; } $debug_str .= _s('Peak memory usage: %s', mem2str($this->getMemoryPeak())) . '<br>'; $debug_str .= _s('Memory limit: %s', ini_get('memory_limit')) . '<br>'; $debug_str .= '<br>'; foreach ($this->apiLog as $i => $apiCall) { $debug_str .= '<div style="border-bottom: 1px dotted gray; margin-bottom: 20px;">'; list($class, $method, $params, $result, $file, $line) = $apiCall; // api method $debug_str .= '<div style="padding-bottom: 10px;">'; $debug_str .= $i + 1 . '. <b>' . $class . '->' . $method . '</b> [' . $file . ':' . $line . ']'; $debug_str .= '</div>'; // parameters $debug_str .= '<table><tr><td style="width: 300px" valign="top">Parameters:'; foreach ($params as $p) { $debug_str .= '<pre>' . print_r(CHtml::encode($p), true) . '</pre>'; } $debug_str .= '</td>'; // result $debug_str .= '<td valign="top">Result:<pre>' . print_r(CHtml::encode($result), true) . '</pre></td>'; $debug_str .= '</tr></table>'; $debug_str .= '</div>'; } $debug_str .= '<br>'; foreach ($this->sqlQueryLog as $query) { $time = $query[0]; $sql = htmlspecialchars($query[1], ENT_QUOTES, 'UTF-8'); if (strpos($sql, 'SELECT ') !== false) { $sqlString = '<span style="color: green; font-size: 1.2em;">' . $sql . '</span>'; } else { $sqlString = '<span style="color: blue; font-size: 1.2em;">' . $sql . '</span>'; } $sqlString = 'SQL (' . $time . '): ' . $sqlString . '<br>'; if ($time > $this->slowSqlQueryTime) { $sqlString = '<b>' . $sqlString . '</b>'; } $debug_str .= $sqlString; $callStackString = '<span style="font-style: italic;">' . $this->formatCallStack($query[2]) . '</span>' . '<br>' . '<br>'; $debug_str .= rtrim($callStackString, '-> ') . '</span>' . '<br>' . '<br>'; } $debug = new CDiv(null, 'textcolorstyles'); $debug->attr('name', 'zbx_debug_info'); $debug->attr('style', 'display: none; overflow: auto; width: 95%; border: 1px #777777 solid; margin: 4px; padding: 4px;'); $debug->addItem(array(BR(), new CJSscript($debug_str), BR())); $debug->show(); }
/** * Make profiling data. * * @return CPre */ public function make() { global $DB; $debug = []; $debug[] = (new CLink())->setAttribute('name', 'debug'); $debug[] = '******************** ' . _('Script profiler') . ' ********************'; $debug[] = BR(); $debug[] = _s('Total time: %1$s', round($this->stopTime - $this->startTime, 6)); $debug[] = BR(); $debug[] = _s('Total SQL time: %1$s', $this->sqlTotalTime); $debug[] = BR(); if (isset($DB) && isset($DB['SELECT_COUNT'])) { $debug[] = _s('SQL count: %1$s (selects: %2$s | executes: %3$s)', count($this->sqlQueryLog), $DB['SELECT_COUNT'], $DB['EXECUTE_COUNT']); $debug[] = BR(); } $debug[] = _s('Peak memory usage: %1$s', mem2str($this->getMemoryPeak())); $debug[] = BR(); $debug[] = _s('Memory limit: %1$s', ini_get('memory_limit')); $debug[] = BR(); $debug[] = BR(); foreach ($this->apiLog as $i => $apiCall) { list($class, $method, $params, $result, $file, $line) = $apiCall; // api method $debug[] = $i + 1 . '. '; $debug[] = bold($class . '.' . $method); $debug[] = $file !== null ? ' [' . $file . ':' . $line . ']' : null; $debug[] = BR(); $debug[] = BR(); // parameters, result $debug[] = (new CTable())->addRow([[_('Parameters') . ':', BR(), print_r($params, true)], [_('Result') . ':', BR(), print_r($result, true)]]); $debug[] = BR(); } $debug[] = BR(); foreach ($this->sqlQueryLog as $query) { $time = $query[0]; $sql = ['SQL (' . $time . '): ', (new CSpan($query[1]))->addClass(substr($query[1], 0, 6) === 'SELECT' ? ZBX_STYLE_GREEN : ZBX_STYLE_BLUE), BR()]; if ($time > $this->slowSqlQueryTime) { $sql = bold($sql); } $debug[] = $sql; $debug[] = $this->formatCallStack($query[2]); $debug[] = BR(); $debug[] = BR(); } return (new CPre())->addClass(ZBX_STYLE_DEBUG_OUTPUT)->setAttribute('name', 'zbx_debug_info')->addStyle('display: none;')->addItem($debug); }
function profiling_stop($type = NULL) { global $starttime; global $memorystamp; global $sqlrequests; global $sqlmark; global $perf_counter; global $var_list; $endtime = COpt::getmicrotime(); $memory = COpt::getmemoryusage(); if (is_null($type)) { $type = 'global'; } echo OBR; if (defined('USE_TIME_PROF')) { echo '(' . $type . ') Time to execute: ' . round($endtime - $starttime[$type], 6) . ' seconds!' . OBR; } if (defined('USE_MEM_PROF')) { echo '(' . $type . ') Memory limit : ' . ini_get('memory_limit') . OBR; echo '(' . $type . ') Memory usage : ' . mem2str($memorystamp[$type]) . ' - ' . mem2str($memory) . OBR; echo '(' . $type . ') Memory leak : ' . mem2str($memory - $memorystamp[$type]) . OBR; } if (defined('USE_VAR_MON')) { $curr_var_list = isset($GLOBALS) ? array_keys($GLOBALS) : array(); $var_diff = array_diff($curr_var_list, $var_list[$type]); echo '(' . $type . ') Undeleted vars : ' . count($var_diff) . ' ['; print_r(implode(', ', $var_diff)); echo ']' . OBR; } if (defined('USE_COUNTER_PROF')) { if (isset($perf_counter[$type])) { ksort($perf_counter[$type]); foreach ($perf_counter[$type] as $name => $value) { echo '(' . $type . ') Counter "' . $name . '" : ' . $value . OBR; } } } if (defined('USE_SQLREQUEST_PROF')) { if (defined('SHOW_SQLREQUEST_DETAILS')) { $requests_cnt = count($sqlrequests); echo '(' . $type . ') SQL requests count: ' . ($requests_cnt - $sqlmark[$type]) . OBR; for ($i = $sqlmark[$type]; $i < $requests_cnt; $i++) { echo '(' . $type . ') SQL request : ' . $sqlrequests[$i] . OBR; } } else { echo '(' . $type . ') SQL requests count: ' . ($sqlrequests - $sqlmark[$type]) . OBR; } } }
public static function profiling_stop($type = NULL) { global $starttime; global $memorystamp; global $sqlrequests; global $sqlmark; global $perf_counter; global $var_list; global $USER_DETAILS; global $DB; if (isset($USER_DETAILS['debug_mode']) && $USER_DETAILS['debug_mode'] == GROUP_DEBUG_MODE_DISABLED) { return; } $endtime = COpt::getmicrotime(); $memory = COpt::getmemoryusage(); if (is_null($type)) { $type = 'global'; } $debug_str = ''; $debug_str .= '<a name="debug"></a>'; $debug_str .= "******************* Stats for {$type} *************************" . OBR; if (defined('USE_TIME_PROF')) { $time = $endtime - $starttime[$type]; if ($time < TOTAL_TIME) { $debug_str .= 'Total time: ' . round($time, 6) . OBR; } else { $debug_str .= '<b>Total time: ' . round($time, 6) . '</b>' . OBR; } } if (defined('USE_MEM_PROF')) { $debug_str .= 'Memory limit : ' . ini_get('memory_limit') . OBR; $debug_str .= 'Memory usage : ' . mem2str($memorystamp[$type]) . ' - ' . mem2str($memory) . OBR; $debug_str .= 'Memory leak : ' . mem2str($memory - $memorystamp[$type]) . OBR; } if (defined('USE_VAR_MON')) { $curr_var_list = isset($GLOBALS) ? array_keys($GLOBALS) : array(); $var_diff = array_diff($curr_var_list, $var_list[$type]); $debug_str .= ' Undeleted vars : ' . count($var_diff) . ' ['; print_r(implode(', ', $var_diff)); $debug_str .= ']' . OBR; } if (defined('USE_COUNTER_PROF')) { if (isset($perf_counter[$type])) { ksort($perf_counter[$type]); foreach ($perf_counter[$type] as $name => $value) { $debug_str .= 'Counter "' . $name . '" : ' . $value . OBR; } } } if (defined('USE_SQLREQUEST_PROF')) { if (defined('SHOW_SQLREQUEST_DETAILS')) { $requests_cnt = count($sqlrequests); $debug_str .= 'SQL selects count: ' . $DB['SELECT_COUNT'] . OBR; $debug_str .= 'SQL executes count: ' . $DB['EXECUTE_COUNT'] . OBR; $debug_str .= 'SQL requests count: ' . ($requests_cnt - $sqlmark[$type]) . OBR; $sql_time = 0; for ($i = $sqlmark[$type]; $i < $requests_cnt; $i++) { $time = $sqlrequests[$i][0]; $sql_time += $time; if ($time < LONG_QUERY) { $debug_str .= 'Time:' . round($time, 8) . ' SQL: ' . $sqlrequests[$i][1] . OBR; } else { $debug_str .= '<b>Time:' . round($time, 8) . ' LONG SQL: ' . $sqlrequests[$i][1] . '</b>' . OBR; } } } else { $debug_str .= 'SQL requests count: ' . ($sqlrequests - $sqlmark[$type]) . OBR; } if ($sql_time < QUERY_TOTAL_TIME) { $debug_str .= 'Total time spent on SQL: ' . round($sql_time, 8) . OBR; } else { $debug_str .= '<b>Total time spent on SQL: ' . round($sql_time, 8) . '</b>' . OBR; } } $debug_str .= "******************** End of {$type} ***************************" . OBR; // DEBUG of ZBX FrontEnd $zbx_debug = new CWidget('debug_hat', new CSpan(new CScript($debug_str), 'textcolorstyles')); $zbx_debug->addHeader(S_DEBUG); $debud = new CDiv(array(BR(), $zbx_debug)); $debud->setAttribute('id', 'zbx_gebug_info'); $debud->setAttribute('style', 'display: none;'); $debud->show(); //---------------- }