Exemple #1
0
function error_handle($type, $message, $run_trace = true)
{
    global $_josh;
    if ($run_trace) {
        $backtrace = debug_backtrace();
        $level = count($backtrace) - 1;
        $message .= " on line " . $backtrace[$level]["line"] . " of file " . $backtrace[$level]["file"];
    }
    if (function_exists("error_email")) {
        $email = $message;
        $email .= "<br><br>Of page: <a href='" . $_josh["request"]["uri"] . "'>" . $_josh["request"]["uri"] . "</a>";
        $email .= "<br><br>Encountered by user: <!--user-->";
        error_email(draw_page($type, $email, true, true));
    }
    if (isset($_josh["mode"]) && $_josh["mode"] == "dev") {
        draw_page($type, $message, true);
    }
}
require_once 'db_lib.php';
$oDB = new db();
if ($oDB->error) {
    // Report a DB connection error
    error_email('Twitter Database Error', 'Unable to connect to Twitter database');
    exit;
}
// Check for new tweets arriving in the tweets table
// TWEET_ERROR_INTERVAL is defined in config.php
$query = 'SELECT COUNT(*) AS cnt FROM tweets ' . 'WHERE created_at > DATE_SUB(NOW( ), ' . 'INTERVAL ' . TWEET_ERROR_INTERVAL . ' MINUTE)';
$result = $oDB->select($query);
$row = mysqli_fetch_assoc($result);
// If there are no new tweets
if ($row['cnt'] == 0) {
    // Get the date and time of the last tweet added
    $query = 'SELECT created_at FROM tweets ' . 'ORDER BY created_at DESC LIMIT 1';
    $result = $oDB->select($query);
    $row = mysqli_fetch_assoc($result);
    $time_since = (time() - strtotime($row['created_at'])) / 60;
    $time_since = (int) $time_since;
    $error_message = 'No tweets added for ' . $time_since . " minutes.";
    $subject = 'Twitter Database Server Error';
    error_email($subject, $error_message);
}
// Email the error message
function error_email($subject, $message)
{
    $to = TWEET_ERROR_ADDRESS;
    $from = "From: Twitter Database Server Monitor <" . TWEET_ERROR_ADDRESS . ">\r\n";
    mail($to, $subject, $message, $from);
}
Exemple #3
0
error_reporting(E_ALL);
ini_set('display_errors', '1');
/**
* monitor_tweets.php
* Check for new tweets in the tweets table and report by email if they aren't found
* Latest copy of this code: http://140dev.com/free-twitter-api-source-code-library/
* @author Adam Green <*****@*****.**>
* @license GNU Public License
* @version BETA 0.20
*/
require_once '140dev_config.php';
require_once 'db_lib.php';
$oDB = new db();
if ($oDB->error) {
    // Report a DB connection error
    error_email('Twitter Database Error', 'Unable to connect to Twitter database');
    exit;
}
// Check for new tweets arriving in the tweets table
// TWEET_ERROR_INTERVAL is defined in 140dev_config.php
/*$query = 'SELECT COUNT(*) AS cnt FROM tweets ' .
  'WHERE created_at > DATE_SUB(NOW( ), ' .
  'INTERVAL ' . TWEET_ERROR_INTERVAL . ' MINUTE)'; */
$del_query = "delete from tweets where LEFT(tweet_text , 2) = 'RT' or LEFT(tweet_text , 1) = '@'";
$result_del = $oDB->select($del_query);
$query = 'SELECT COUNT(*) AS cnt FROM tweets ';
$result = $oDB->select($query);
$row = mysqli_fetch_assoc($result);
// If there are no new tweets
if ($row['cnt'] < 11) {
    // Get the date and time of the last tweet added