Hi - I am running 3.5.4 and these two cron jobs are REALLY slowing down my forums for up to 2 minutes at a time. Is there any reason I can't change these to run once a day? Is there anything I can comment out? Here's what I have in them:
cleanup.php:
PHP Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.5.4 - Licence Number XXXXXXXXXX
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000-2006 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval(TIMENOW - $vbulletin->options['cookietimeout']) . "
### Delete stale sessions ###
");
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "cpsession
WHERE dateline < " . intval(TIMENOW - 3600) . "
### Delete stale cpsessions ###
");
//searches expire after one hour
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "search
WHERE dateline < " . (TIMENOW - 3600) . "
### Remove stale searches ###
");
// expired lost passwords and email confirmations after 4 days
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "useractivation
WHERE dateline < " . (TIMENOW - 345600) . " AND
(type = 1 OR (type = 0 and usergroupid = 2))
### Delete stale password and email confirmation requests ###
");
// old forum/thread read marking data
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "threadread
WHERE readtime < " . (TIMENOW - ($vbulletin->options['markinglimit'] * 3600))
);
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "forumread
WHERE readtime < " . (TIMENOW - ($vbulletin->options['markinglimit'] * 3600))
);
//[p:cron_script_cleanup]
if ($vbulletin->options['vbpager_delete_read'])
{
if (!function_exists("vbpager_totalpager"))
{
function vbpager_totalpager($userid = 0)
{
global $vbulletin;
if ($userid > 0)
{
$result = $vbulletin->db->query_first("SELECT count(*) AS totalpager
FROM " . TABLE_PREFIX . "pagerreceipt
WHERE (userid = $userid AND active = 1 )
OR (touserid = $userid AND markdeleted = 0)");
$totalpager = intval($result['totalpager']);
return $totalpager;
}
return 0;
}
}
if (!function_exists("vbpager_totalunread"))
{
function vbpager_totalunread($userid = 0)
{
global $vbulletin;
if ($userid > 0)
{
$result = $vbulletin->db->query_first("SELECT count(*) AS totalpager
FROM " . TABLE_PREFIX . "pagerreceipt
WHERE (touserid = $userid AND markdeleted = 0)
AND readtime = 0");
$totalpager = intval($result['totalpager']);
return $totalpager;
}
}
}
if (!function_exists("vbpager_updatedb"))
{
function vbpager_updatedb($uid = 0)
{
global $vbulletin;
$pagerusers = $vbulletin->db->query_read("SELECT userid
FROM " . TABLE_PREFIX . "user " .
iif($uid > 0, " WHERE userid = '$uid' ", ' ') . "
ORDER BY userid");
$i = 0;
while ($pageruser = $vbulletin->db->fetch_array($pagerusers))
{
$userid = $pageruser['userid'];
$sumpager = vbpager_totalpager($userid);
$unreadsum = vbpager_totalunread($userid);
$i++;
$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET
pagertotal = '$sumpager', pagerunread = '$unreadsum'
WHERE userid = $userid ");
}
return $i;
}
}
// Orphaned pagertext records are removed after one hour.
// When we delete PAGERs we only delete the pager record, leaving
// the pagertext record alone for this script to clean up
$result = $vbulletin->db->query("
UPDATE " . TABLE_PREFIX . "pagerreceipt
SET markdeleted =1, active = 0 WHERE readtime > 0");
}
$result = $vbulletin->db->query("
DELETE FROM " . TABLE_PREFIX . "pagerreceipt
WHERE active = 0 AND markdeleted = 1");
$pagertexts = $vbulletin->db->query_read("
SELECT p.pagerid FROM " . TABLE_PREFIX . "pagertext AS p
LEFT JOIN " . TABLE_PREFIX . "pagerreceipt AS r
USING (pagerid) WHERE r.pagerid is NULL");
if ($vbulletin->db->num_rows($pagertexts))
{
$pids = '0';
while ($pager = $vbulletin->db->fetch_array($pagertexts))
{
$pids .= ",$pager[pagerid]";
}
$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "pagertext WHERE pagerid IN($pids)");
}
$vbulletin->db->free_result($pagertexts);
if ($vbulletin->options['vbpager_delete_read'])
{
$result = vbpager_updatedb();
}
//[/p:cron_script_cleanup]
log_cron_action('Hourly Cleanup #1 Completed', $nextitem);
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 10:18, Tue Aug 15th 2006
|| # CVS: $RCSfile: cleanup.php,v $ - $Revision: 1.33 $
|| ####################################################################
\*======================================================================*/
?>
cleanup2.php:
PHP Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.5.4 - Licence Number XXXXXXXXXXX
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000-2006 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "session
WHERE lastactivity < " . intval(TIMENOW - $vbulletin->options['cookietimeout']) . "
### Delete stale sessions ###
");
// posthashes are only valid for 5 minutes
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "posthash
WHERE dateline < " . (TIMENOW - 300)
);
// expired registration images after 1 hour
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "regimage
WHERE dateline < " . (TIMENOW - 3600)
);
// expired cached posts
$vbulletin->db->query_write("
DELETE FROM " . TABLE_PREFIX . "post_parsed
WHERE dateline < " . (TIMENOW - ($vbulletin->options['cachemaxage'] * 60 * 60 * 24))
);
// Orphaned Attachments are removed after one hour
$attachdata =& datamanager_init('Attachment', $vbulletin, ERRTYPE_SILENT);
$attachdata->set_condition("attachment.postid = 0 AND attachment.dateline < " . (TIMENOW - 3600));
$attachdata->delete();
// Orphaned pmtext records are removed after one hour.
// When we delete PMs we only delete the pm record, leaving
// the pmtext record alone for this script to clean up
$pmtexts = $vbulletin->db->query_read("
SELECT pmtext.pmtextid
FROM " . TABLE_PREFIX . "pmtext AS pmtext
LEFT JOIN " . TABLE_PREFIX . "pm AS pm USING(pmtextid)
WHERE pm.pmid IS NULL
");
if ($vbulletin->db->num_rows($pmtexts))
{
$pmtextids = '0';
while ($pmtext = $vbulletin->db->fetch_array($pmtexts))
{
$pmtextids .= ",$pmtext[pmtextid]";
}
$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "pmtext WHERE pmtextid IN($pmtextids)");
}
$vbulletin->db->free_result($pmtexts);
log_cron_action('Hourly Cleanup #2 Completed', $nextitem);
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 10:18, Tue Aug 15th 2006
|| # CVS: $RCSfile: cleanup2.php,v $ - $Revision: 1.23 $
|| ####################################################################
\*======================================================================*/
?>