[code filename="cron.php"]<?php
define('IN_CRON', true);
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'common.php');
$cron_type = request_var('cron_type', '');
$use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false;
// Output transparent gif
header('Cache-Control: no-cache');
header('Content-type: image/gif');
header('Content-length: 43');
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
flush();
/**
* Run cron-like action
* Real cron-based layer will be introduced in 3.2
*/
switch ($cron_type)
{
case 'stats':
if (time() - '600' > $board_config['last_stats_run'])
{
$total_posts = get_db_stat('postcount');
$total_users = get_db_stat('usercount');
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '" . str_replace("\'", "''", $total_posts) . "'
WHERE config_name = 'total_posts'";
if( !$db->sql_query($sql) )
{
die("Failed to update posts stat");
}
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '" . str_replace("\'", "''", $total_users) . "'
WHERE config_name = 'total_users'";
if( !$db->sql_query($sql) )
{
die("Failed to update users stat");
}
// Set last run time
$time = time();
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '" . str_replace("\'", "''", $time) . "'
WHERE config_name = 'last_stats_run'";
if( !$db->sql_query($sql) )
{
die("Failed to update last stats run time");
}
@unlink('cache/config_table.php'); // This is my config table cache file
}
break;
}
// Unloading cache and closing db after having done the dirty work.
if ($use_shutdown_function)
{
register_shutdown_function('garbage_collection');
}
else
{
garbage_collection();
}
exit;
?>[/code]
i have changed this in index.php:
- Code: Select all
//$total_posts = get_db_stat('postcount'); // These have been moved to
//$total_users = get_db_stat('usercount'); // board_config by cron script
$total_posts = $board_config['total_posts'];
$total_users = $board_config['total_users'];
i have added to DB this:
- Code: Select all
INSERT INTO phpbb_config (config_name, config_value) VALUES ('last_stats_run', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('total_posts', ''), ('total_users', '');
in page_tail.php i have added this above "$template->pparse('overall_footer');":
- Code: Select all
// Call cron-type script
if (!defined('IN_CRON'))
{
$cron_type = '';
if (time() - '600' > $board_config['last_stats_run'])
{
// Do stats
$cron_type = 'stats';
}
cron_type)
{
$template->assign_var('RUN_CRON_TASK', '<img src="' . $phpbb_root_path . 'cron.' . $phpEx . '?cron_type=' . $cron_type . '" width="1" height="1" />');
}
}
i have added this to the includes/functions.php:
- Code: Select all
/**
* set_var
*
* Set variable, used by {@link request_var the request_var function}
*
* @access: private
*/
function set_var(&$result, $var, $type, $multibyte = false)
{
settype($var, $type);
$result = $var;
if ($type == 'string')
{
$result = trim(htmlspecialchars(str_replace(array("\r\n", "\r"), array("\n", "\n"), $result)));
$result = (STRIP) ? stripslashes($result) : $result;
// Check for possible multibyte characters to save a preg_replace call if nothing is in there...
if ($multibyte && strpos($result, '&#') !== false)
{
$result = preg_replace('#&(\#[0-9]+;)#', '&\1', $result);
}
}
}
/**
* request_var
*
* Used to get passed variable
*/
function request_var($var_name, $default, $multibyte = false)
{
if (!isset($_REQUEST[$var_name]) || (is_array($_REQUEST[$var_name]) && !is_array($default)) || (is_array($default) && !is_array($_REQUEST[$var_name])))
{
return (is_array($default)) ? array() : $default;
}
$var = $_REQUEST[$var_name];
if (!is_array($default))
{
$type = gettype($default);
}
else
{
list($key_type, $type) = each($default);
$type = gettype($type);
$key_type = gettype($key_type);
}
if (is_array($var))
{
$_var = $var;
$var = array();
foreach ($_var as $k => $v)
{
if (is_array($v))
{
foreach ($v as $_k => $_v)
{
set_var($k, $k, $key_type);
set_var($_k, $_k, $key_type);
set_var($var[$k][$_k], $_v, $type, $multibyte);
}
}
else
{
set_var($k, $k, $key_type);
set_var($var[$k], $v, $type, $multibyte);
}
}
}
else
{
set_var($var, $var, $type, $multibyte);
}
return $var;
}
and the last step, i have added this into the overall_footer.tpl:
- Code: Select all
{RUN_CRON_TASK}
My problem is, that this cron is not working, if i do all this steps, the index stats for total posts and users are at "0"

