public static function High_Load_Monitor() { //-- if (is_array(self::$HighLoadMonitorStats)) { return (array) self::$HighLoadMonitorStats; // avoid re-run and serve from cache } //end if //-- $tmp_sysload_avg = array(); //-- if (defined('SMART_FRAMEWORK_NETSERVER_MAXLOAD')) { $tmp_max_load = (int) SMART_FRAMEWORK_NETSERVER_MAXLOAD; } else { $tmp_max_load = 0; } //end if if ($tmp_max_load > 0) { // run only if set to a value > 0 if (function_exists('sys_getloadavg')) { $tmp_sysload_avg = (array) @sys_getloadavg(); $tmp_sysload_avg[0] = (int) $tmp_sysload_avg[0]; if ($tmp_sysload_avg[0] > $tmp_max_load) { // protect against system overload over max if (!headers_sent()) { http_response_code(503); } else { Smart::log_notice('#SMART-FRAMEWORK-HIGH-LOAD-PROTECT#' . "\n" . 'SmartFramework // Web :: System Overload Protection: The System is Too Busy ... Try Again Later. The Load Averages reached the maximum allowed value by current settings ... [' . $tmp_sysload_avg[0] . ' of ' . $tmp_max_load . ']'); } //end if else die(SmartComponents::http_message_503_serviceunavailable('<h1>503 Service Unavailable - Too busy, try again later</h1><br><b>SmartFramework // Web :: System Overload Protection</b><br>The Load Averages reached the maximum allowed value by current settings ...')); } //end if } //end if } //end if //-- self::$HighLoadMonitorStats = (array) $tmp_sysload_avg; //-- return (array) self::$HighLoadMonitorStats; //-- }
public static final function Raise503Error($y_msg) { //-- if (!headers_sent()) { http_response_code(503); } else { Smart::log_warning('Headers Already Sent before 503 ...'); } //end if else die(SmartComponents::http_message_503_serviceunavailable(Smart::escape_html((string) $y_msg))); //-- }