diff --git a/lib/database.php b/lib/database.php
index 080883a9c..69c43a655 100644
--- a/lib/database.php
+++ b/lib/database.php
@@ -201,7 +201,7 @@ function db_execute_prepared($sql, $params = array(), $log = true, $db_conn = fa
$sql = db_strip_control_chars($sql);
if (!empty($config['DEBUG_SQL_CMD'])) {
- cacti_log('DEVEL: SQL ' . $execute_name . ': "' . $sql . '"', false, 'DBCALL', POLLER_VERBOSITY_DEVDBG);
+ db_echo_sql('db_' . $execute_name . ': "' . $sql . "\"\n");
}
$errors = 0;
@@ -213,6 +213,10 @@ function db_execute_prepared($sql, $params = array(), $log = true, $db_conn = fa
$code = 0;
$en = '';
+ if (!empty($config['DEBUG_SQL_CMD'])) {
+ db_echo_sql('db_' . $execute_name . ' Memory [Before]: ' . memory_get_usage() . ' / ' . memory_get_peak_usage() . "\n");
+ }
+
set_error_handler('db_warning_handler',E_WARNING | E_NOTICE);
try {
if (empty($params) || cacti_count($params) == 0) {
@@ -227,6 +231,10 @@ function db_execute_prepared($sql, $params = array(), $log = true, $db_conn = fa
}
restore_error_handler();
+ if (!empty($config['DEBUG_SQL_CMD'])) {
+ db_echo_sql('db_' . $execute_name . ' Memory [ After]: ' . memory_get_usage() . ' / ' . memory_get_peak_usage() . "\n");
+ }
+
if ($code == 0) {
$code = $query->errorCode();
if ($code > 0) {
@@ -1314,7 +1322,5 @@ function db_check_password_length() {
function db_echo_sql($line, $force = false) {
global $config;
- if (!empty($config['DEBUG_SQL_FLOW'])) {
- file_put_contents(sys_get_temp_dir() . '/cacti-sql.log', get_debug_prefix() . $line, FILE_APPEND);
- }
+ file_put_contents(sys_get_temp_dir() . '/cacti-sql.log', get_debug_prefix() . $line, FILE_APPEND);
}
diff --git a/lib/functions.php b/lib/functions.php
index b505eacc4..644d03ad2 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -161,7 +161,7 @@ function set_user_setting($config_name, $value, $user = -1) {
}
if ($user == -1) {
- cacti_log('Attempt to set user setting \'' . $config_name . '\', with no user id: ' . cacti_debug_backtrace('', false, false), false, 'WARNING:');
+ cacti_log('Attempt to set user setting \'' . $config_name . '\', with no user id: ' . cacti_debug_backtrace('', false, false, 0, 1), false, 'WARNING:');
} else {
db_execute_prepared('REPLACE INTO settings_user
SET user_id = ?,
@@ -381,7 +381,7 @@ function read_config_option($config_name, $force = false) {
}
if (!empty($config['DEBUG_READ_CONFIG_OPTION'])) {
- file_put_contents(sys_get_temp_dir() . '/cacti-option.log', get_debug_prefix() . cacti_debug_backtrace($config_name, false, false) . "\n", FILE_APPEND);
+ file_put_contents(sys_get_temp_dir() . '/cacti-option.log', get_debug_prefix() . cacti_debug_backtrace($config_name, false, false, 0, 1) . "\n", FILE_APPEND);
}
// Do we have a value already stored in the array, or
@@ -747,6 +747,7 @@ function cacti_log_file() {
if ($logfile == '') {
$logfile = $config['base_path'] . '/log/cacti.log';
}
+ $config['log_path'] = $logfile;
return $logfile;
}
@@ -3708,14 +3709,18 @@ function update_system_mibs($host_id) {
}
}
-function cacti_debug_backtrace($entry = '', $html = false, $record = true, $limit = 0, $skip = 1) {
+function cacti_debug_backtrace($entry = '', $html = false, $record = true, $limit = 0, $skip = 0) {
global $config;
- $skip = $skip > 0 ? $skip : 1;
+ $skip = $skip >= 0 ? $skip : 1;
$limit = $limit > 0 ? ($limit + $skip) : 0;
$callers = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $limit);
- array_shift($callers);
+ while ($skip > 0) {
+ array_shift($callers);
+ $skip--;
+ }
+
$s='';
foreach ($callers as $c) {
if (isset($c['line'])) {
@@ -4058,7 +4063,7 @@ function CactiErrorHandler($level, $message, $file, $line, $context) {
case E_ERROR:
case E_PARSE:
cacti_log($error, false, 'ERROR');
- cacti_debug_backtrace('PHP ERROR PARSE');
+ cacti_debug_backtrace('PHP ERROR PARSE', false, true, 0, 1);
if ($plugin != '') {
api_plugin_disable_all($plugin);
cacti_log("ERRORS DETECTED - DISABLING PLUGIN '$plugin'");
@@ -4068,27 +4073,27 @@ function CactiErrorHandler($level, $message, $file, $line, $context) {
case E_RECOVERABLE_ERROR:
case E_USER_ERROR:
cacti_log($error, false, 'ERROR');
- cacti_debug_backtrace('PHP ERROR');
+ cacti_debug_backtrace('PHP ERROR', false, true, 0, 1);
break;
case E_COMPILE_WARNING:
case E_CORE_WARNING:
case E_USER_WARNING:
case E_WARNING:
cacti_log($error, false, 'ERROR');
- cacti_debug_backtrace('PHP ERROR WARNING');
+ cacti_debug_backtrace('PHP ERROR WARNING', false, true, 0, 1);
break;
case E_NOTICE:
case E_USER_NOTICE:
cacti_log($error, false, 'ERROR');
- cacti_debug_backtrace('PHP ERROR NOTICE');
+ cacti_debug_backtrace('PHP ERROR NOTICE', false, true, 0, 1);
break;
case E_STRICT:
cacti_log($error, false, 'ERROR');
- cacti_debug_backtrace('PHP ERROR STRICT');
+ cacti_debug_backtrace('PHP ERROR STRICT', false, true, 0, 1);
break;
default:
cacti_log($error, false, 'ERROR');
- cacti_debug_backtrace('PHP ERROR');
+ cacti_debug_backtrace('PHP ERROR', false, true, 0, 1);
}
return false;
@@ -4118,7 +4123,7 @@ function CactiShutdownHandler () {
' in file: ' . $error['file'] . ' on line: ' . $error['line'];
cacti_log($message, false, 'ERROR');
- cacti_debug_backtrace('PHP ERROR');
+ cacti_debug_backtrace('PHP ERROR', false, true, 0, 1);
if ($plugin != '') {
api_plugin_disable_all($plugin);
diff --git a/lib/installer.php b/lib/installer.php
index 5049f7ff5..55fa343d2 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -1555,25 +1555,85 @@ class Installer implements JsonSerializable {
$output .= Installer::sectionSubTitleEnd();
+ $output .= Installer::sectionSubTitle(__('PHP - Recommendations'), 'php_recommends');
+
+ $rec_version = '5.4.0';
+ $rec_memory_mb = (version_compare(PHP_VERSION, '7.0.0', '<') ? 800 : 400);
+ $rec_execute_m = 5;
+
+ $rec_memory = $rec_memory_mb * 1024 * 1024;
+ $rec_execute = $rec_execute_m * 60;
+ $memory_limit = str_replace('M', '', ini_get('memory_limit'));
+ $execute_time = ini_get('max_execution_time');
+
+ $recommends = array(
+ array(
+ 'name' => 'version',
+ 'value' => $rec_version,
+ 'current' => PHP_VERSION,
+ 'status' => version_compare(PHP_VERSION, $rec_version, '>=') ? DB_STATUS_SUCCESS : DB_STATUS_ERROR,
+ 'description' => __('PHP %s is the mimimum version', $rec_version),
+ ),
+ array(
+ 'name' => 'memory_limit',
+ 'value' => $rec_memory_mb . 'M',
+ 'current' => $memory_limit . 'M',
+ 'status' => ($memory_limit <= 0 || $memory_limit >= $rec_memory_mb) ? DB_STATUS_SUCCESS : DB_STATUS_ERROR,
+ 'description' => __('A minimum of %s MB memory limit', $rec_memory_mb),
+ ),
+ array(
+ 'name' => 'max_execution_time',
+ 'value' => $rec_execute,
+ 'current' => $execute_time,
+ 'status' => ($execute_time <= 0 || $execute_time >= $rec_execute) ? DB_STATUS_SUCCESS : DB_STATUS_ERROR,
+ 'description' => __('A minimum of %s m execution time', $rec_execute_m),
+ ),
+ );
+
+ ob_start();
+
+ html_start_box(__('PHP Recommendations'), '100%', false, '4', '', false);
+ html_header(array(__('Name'), __('Current'), __('Recommended'), __('Status'), __('Description')));
+
+ $status = DB_STATUS_SUCCESS;
+ foreach ($recommends as $recommend) {
+ if ($recommend['status'] == DB_STATUS_SUCCESS) {
+ $status_font = 'green';
+ $status_text = __('Passed');
+ } else {
+ $status_font = 'red';
+ $status_text = __('Warning');
+ $status = DB_STATUS_WARNING;
+ }
+
+ form_alternate_row('php_' . $recommend['name'],true);
+ form_selectable_cell($recommend['name'], '');
+ form_selectable_cell($recommend['current'], '');
+ form_selectable_cell('>= ' . $recommend['value'], '');
+ form_selectable_cell("$status_text", '');
+ form_selectable_cell($recommend['description'], '');
+ form_end_row();
+ }
+
+ html_end_box(false);
+
+ $output .= Installer::sectionNormal(ob_get_contents());
+ ob_clean();
+
+ $output .= Installer::sectionSubTitleEnd();
+ $enabled['php_recommends'] = $status;
+
$output .= Installer::sectionSubTitle(__('PHP - Module Support (Required)'), 'php_modules');
$output .= Installer::sectionNormal(__('Cacti requires several PHP Modules to be installed to work properly. If any of these are not installed, you will be unable to continue the installation until corrected. In addition, for optimal system performance Cacti should be run with certain MySQL system variables set. Please follow the MySQL recommendations at your discretion. Always seek the MySQL documentation if you have any questions.'));
$output .= Installer::sectionNormal(__('The following PHP extensions are mandatory, and MUST be installed before continuing your Cacti install.'));
- ob_start();
+ ob_clean();
html_start_box(__('Required PHP Modules'), '100%', false, '3', '', false);
html_header(array(__('Name'), __('Required'), __('Installed')));
- $enabled['php_modules'] = version_compare(PHP_VERSION, '5.4.0', '<') ? DB_STATUS_ERROR : DB_STATUS_SUCCESS;
- form_alternate_row('phpline',true);
- form_selectable_cell(__('PHP Version'), '');
- form_selectable_cell('5.4.0+', '');
- form_selectable_cell((version_compare(PHP_VERSION, '5.4.0', '<') ? "" . PHP_VERSION . "" : "" . PHP_VERSION . ""), '');
- form_end_row();
-
- $output .= Installer::sectionNormal(ob_get_contents());
- ob_clean();
+ $enabled['php_modules'] = DB_STATUS_SUCCESS;
foreach ($this->modules as $id =>$e) {
form_alternate_row('line' . $id);