function runJob($job)
{
    global $debug, $sendLogToEmail, $resultsSummary, $jobdir;
    $resultsSummary = "";
    $lastActual = $job["lastActual"];
    $lastScheduled = $job["lastScheduled"];
    if ($lastScheduled > $lastActual) {
        logMessage("Running\t" . $job[PC_CRONLINE]);
        logMessage("  Last run:\t" . date("r", $lastActual));
        logMessage("  Last scheduled:\t" . date("r", $lastScheduled));
        $argv = $job[PC_ARGS];
        $jobData = getJobTempData($job);
        $benchmark = job_benchmark_start();
        ob_start();
        include CRON_PATH . $job[PC_CMD];
        $return = trim(ob_get_contents());
        ob_end_clean();
        $seconds = job_benchmark_end($benchmark);
        if ($debug) {
            echo $return;
        }
        if (!empty($return)) {
            logMessage("  Script returned:\t" . makeOneLine($return));
        }
        logMessage("  Execution time:\t{$seconds} seconds");
        markLastRun($job, $lastScheduled, $jobData);
        logMessage("Completed\t" . $job[PC_CRONLINE]);
        if ($sendLogToEmail != "") {
            mail($sendLogToEmail, "[cron] " . $job[PC_COMMENT], $resultsSummary);
        }
        return true;
    } else {
        if ($debug) {
            logMessage("Skipping\t" . $job[PC_CRONLINE]);
            logMessage("  Last run:\t" . date("r", $lastActual));
            logMessage("  Last scheduled:\t" . date("r", $lastScheduled));
            logMessage("Completed\t" . $job[PC_CRONLINE]);
        }
        return false;
    }
}
/**
 * Error handler that logs only the error messages to a file and continues with the standard php error handler.
 */
function log_handler($errno, $errtext, $errfile, $errline)
{
    $replevel = error_reporting();
    // If the @ error suppression operator was used, error_reporting is temporarily set to 0
    if ($replevel == 0) {
        return;
    }
    // This checks whether the error should be shown - according to what we set before with error_reporting()
    if (($errno & $replevel) != $errno) {
        return;
    }
    // Ignore the error when it is a DB error (already saved to sql log file)
    if (preg_match("~^DB ERROR \\d+\\:~i", $errtext)) {
        return;
    }
    $errlogfile = 'data/errlog_php.inc.php';
    if (file_exists($errlogfile) == false) {
        $errlogfile = $config['fpath'] . '/' . $errlogfile;
    }
    if (file_exists($errlogfile)) {
        $lines = file($errlogfile);
        foreach ($lines as $key => $value) {
            $value = trim($value);
            if (empty($value)) {
                unset($lines[$key]);
            } else {
                $lines[$key] = $value;
                // Also trim it for the file
            }
        }
    } else {
        $lines = array();
    }
    if (viscacha_function_exists('debug_backtrace')) {
        $backtrace = debug_backtrace();
        foreach ($backtrace as $key => $value) {
            unset($value['args']);
            unset($value['object']);
            $backtrace[$key] = $value;
            /*
            function  	string  	 The current function name. See also __FUNCTION__.
            line 	integer 	The current line number. See also __LINE__.
            file 	string 	The current file name. See also __FILE__.
            class 	string 	The current class name. See also __CLASS__
            object 	object 	The current object.
            type 	string 	The current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned.
            */
        }
    } else {
        $backtrace = array();
    }
    $cols = array($errno, makeOneLine($errtext), $errfile, $errline, makeOneLine($_SERVER['REQUEST_URI']), time(), base64_encode(serialize($backtrace)));
    $lines[] = implode("\t", $cols);
    @file_put_contents($errlogfile, implode("\n", $lines));
    return false;
    // Return to php error handler
}
 function error($errcomment)
 {
     // Try to get better results for line and file.
     if (viscacha_function_exists('debug_backtrace') == true) {
         $backtraceInfo = debug_backtrace();
         // 0 is class.mysql.php, 1 is the calling code...
         if (isset($backtraceInfo[1]) == true) {
             $errline = $backtraceInfo[1]['line'];
             $errfile = $backtraceInfo[1]['file'];
         }
     }
     if ($this->logerrors) {
         if (file_exists($this->errlogfile)) {
             $lines = file($this->errlogfile);
             foreach ($lines as $key => $value) {
                 $value = trim($value);
                 if (empty($value)) {
                     unset($lines[$key]);
                 } else {
                     $lines[$key] = $value;
                     // Also trim it for the file
                 }
             }
         } else {
             $lines = array();
         }
         $cols = array($this->errno(), makeOneLine($this->errstr()), $errfile, $errline, makeOneLine($_SERVER['REQUEST_URI']), time(), makeOneLine($errcomment));
         $lines[] = implode("\t", $cols);
         @file_put_contents($this->errlogfile, implode("\n", $lines));
     }
     $errcomment = nl2br($errcomment);
     return "DB ERROR " . $this->errno() . ": " . $this->errstr() . "<br />File: {$errfile} on line {$errline}<br />Query: <code>{$errcomment}</code>";
 }
/**
 * Error handler that logs only the error messages to a file and continues with the standard php error handler.
 */
function log_handler($errno, $errtext, $errfile, $errline)
{
    $replevel = error_reporting();
    // If the @ error suppression operator was used, error_reporting is temporarily set to 0
    if ($replevel == 0) {
        return;
    }
    // This checks whether the error should be shown - according to what we set before with error_reporting()
    if (($errno & $replevel) != $errno) {
        return;
    }
    $errlogfile = 'data/errlog_php.inc.php';
    if (file_exists($errlogfile) == false) {
        $errlogfile = $config['fpath'] . '/' . $errlogfile;
    }
    if (file_exists($errlogfile)) {
        $lines = file($errlogfile);
        foreach ($lines as $key => $value) {
            $value = trim($value);
            if (empty($value)) {
                unset($lines[$key]);
            } else {
                $lines[$key] = $value;
                // Also trim it for the file
            }
        }
    } else {
        $lines = array();
    }
    $cols = array($errno, makeOneLine($errtext), $errfile, $errline, makeOneLine($_SERVER['REQUEST_URI']), time(), PHP_VERSION . " (" . PHP_OS . ")");
    $lines[] = implode("\t", $cols);
    @file_put_contents($errlogfile, implode("\n", $lines));
    return false;
    // Return to php error handler
}