function cx_email_error($a_error) { $errors = "The following errors occured:\r\n "; if (is_array($a_error)) { foreach ($a_error as $error) { $errors .= $error . "\r\n"; } } elseif (is_object($a_error)) { $errors .= serialize($a_error); } elseif (is_string($a_error)) { $errors .= $a_error; } else { return false; } // Only send error to email once per day!! $file = CX_BASE_DIR . 'last_error.txt'; $lines = file_exists($file) ? file_get_contents($file) : ''; $date = date('m/d/Y'); if (substr_count($lines, $date) > 0) { return false; } // Save date to last_error, to prevent further error reports. $worked = file_put_contents($file, $date, LOCK_EX); if ($worked === false) { return false; // Avoid repeated messages as it did NOT update correctly! } $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers if (defined('CX_SYSTEM_ADMIN_NAME')) { $to = CX_SYSTEM_ADMIN_NAME; } else { $to = CX_SYSTEM_ADMIN_EMAIL; } if (defined('CX_SITE_NAME')) { $site = CX_SITE_NAME; } else { $site = 'system'; } $email = CX_SYSTEM_ADMIN_EMAIL; $subject = 'System error in ' . $site; $from = 'noreply@' . str_replace(" ", "_", $site); $headers .= 'To: ' . $to . ' <' . CX_SYSTEM_ADMIN_EMAIL . '>' . "\r\n"; $headers .= 'From: ' . $site . ' <' . $from . '>' . "\r\n"; if (cx_is_local_and_live() === true) { echo "Error...see log file for more info."; error_log($errors, 3, CX_LOGS_DIR . "cx.log"); return false; } if (cx_is_local_and_not_live() === true) { echo "Emails would have been sent to: {$email} <br>"; echo "Subject: {$subject} <br>"; echo "MSG: {$errors} <br>"; return false; } mail($email, $subject, $errors, $headers); // cx_twilio($errors); }
function cx_live_check() { if (!defined('CX_LIVE')) { if (cx_is_local_and_not_live() === true) { define("CX_LIVE", false); // Show me my errors } else { define("CX_LIVE", true); // Its in production mode, show default error page } } if (!defined('CX_DEBUG_MAIL')) { if (cx_is_local_and_not_live() === true) { define('CX_DEBUG_MAIL', true); // not live, so echo email } else { define('CX_DEBUG_MAIL', false); // live, so send real emails out } } }
public function __construct($options = array()) { if (isset($options['ttl'])) { $this->ttl = intval($options['ttl']); } elseif (defined('CACHE_TTL')) { $this->ttl = CACHE_TTL; } else { $this->ttl = self::EXPIRES_IN_SECONDS_DEFAULT; } if ($this->ttl > self::MONTH_IN_SECONDS) { $this->ttl = self::MONTH_IN_SECONDS; } if (cx_is_local_and_not_live() === true) { $this->cache = ''; return false; } if (isset($options['engine'])) { $engine = $options['engine']; } elseif (defined('CACHE_ENGINE')) { $engine = CACHE_ENGINE; } else { $engine = 'auto'; } switch ($engine) { case 'none': $this->cache = ''; break; case 'file': $this->cache = $this->load_class('cx\\cache\\file'); case 'redis': $this->cache = $this->load_class('cx\\cache\\redis_cache'); break; case 'op': $this->cache = $this->load_class('cx\\cache\\opcache'); break; case 'apc': $this->cache = $this->load_class('cx\\cache\\apc'); break; case 'xcache': $this->cache = $this->load_class('cx\\cache\\xcache'); break; case 'memcached': $this->cache = $this->load_class('cx\\cache\\memcached'); break; case 'auto': default: if (class_exists('Redis')) { $this->cache = $this->load_class('cx\\cache\\redis_cache'); // } elseif (extension_loaded('Zend OPcache')) { // $this->cache = $this->load_class('cx\cache\opcache'); } elseif (extension_loaded('apc')) { $this->cache = $this->load_class('cx\\cache\\apc'); } elseif (function_exists('xcache_isset')) { $this->cache = $this->load_class('cx\\cache\\xcache'); } elseif (class_exists('Memcached') && function_exists('memcached_servers')) { $this->cache = $this->load_class('cx\\cache\\memcached'); } else { $this->cache = ''; } break; } }
private function end_fn($a) { $alert = $a['alert']; $output = $a['output']; $end_time = cx_timer(CX_START_TIME); if ($end_time['time'] > CX_TIMEOUT) { if ($this->do_time_alerts === true) { $msg = "Server is slow...{$end_time['string']}"; $alert .= "cx_log('{$msg}');\r\n"; $output .= cx_is_local_and_not_live() === true ? "{$msg} <br>\r\n" : "<!-- {$msg} -->\r\n"; } } else { $output .= "<!-- Server is fine...{$end_time['string']} -->\r\n"; } if (!empty($alert)) { $output .= $this->inline_js($alert); } return $output; }