Location: PHPKode > projects > web-cp - Web Hosting Control Panel > webcp/server/cron.php
<?	/*
	// File:	cron.php
	// Purpose:	web://cp tasks scheduler
	// Creation:	2002-02-28
	// Author:	Felix <hide@address.com>
	*/

// Get current time
$minute = date("i");
$hour = date("H");
$day = date("j");
$week = date("w");

// Indicate the backend is up
touch($cfg['basedir'].$cfg['statustag']);

// Connect to database
if (!mysql_connect($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpass'])) {
	sleep(1);
	if(!mysql_connect($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpass'])) {
		webcp_log(0,0,"cron","Could not connect to database server",0);
	}
}
mysql_select_db($cfg['dbname']);


//
// Run hourly tasks
if ($minute == $cfg['cron_hourly']['minute']) {
	// Run group quota, user quota and transfer quota check
	include('cron/quota.inc.phps');
	
	webcp_log(2,0,"cron","Hourly scheduled tasks ran",0);
}


//
// Run multi-daily tasks
if ($minute == $cfg['cron_multidaily']['minute'] AND (in_array($hour, $cfg['cron_multidaily']['hour']))) {
	// Update logrotate conf file
	include('cron/logrotate.inc.phps');
	
	webcp_log(2,0,"cron","multi-daily scheduled tasks ran",0);
}


//
// Run daily tasks
if ($minute == $cfg['cron_daily']['minute'] AND $hour == $cfg['cron_daily']['hour']) {
	// Clean up update count
	mysql_query("UPDATE users SET ucount = 0");
	mysql_query("UPDATE domains SET ucount = 0");
	
	webcp_log(2,0,"cron","Daily scheduled tasks ran",0);

	// Run web stats (webalizer, wusage, etc)
	include('cron/webalizer.inc.phps');

	// Run scheduled backups
	$pid = pcntl_fork();
	webcp_log(3,0,'webcp.php',"Note: Forking schedbackups.php",0,$echo);
	if ($pid == -1) {
		webcp_log(0,0,"webcp.php","Fork Error: could not fork webcp.php for schedbackups.php",0,$echo);
	} elseif (!$pid) {

		// Log Process ID
		$fp = fopen($cfg['pid'].'-backup',"w+");
		$mypid = getmypid();
		fwrite($fp,$mypid);
		fflush($fp);
		fclose($fp);

		// Set no timeout (unlimited)
		set_time_limit(0);

		$schedbackups = "Daily";
		// include cron script and stay there
		include("cron/schedbackups.inc.phps");
		exit;
	}
}


//
// Run weekly tasks
if ($minute == $cfg['cron_weekly']['minute'] AND $hour == $cfg['cron_weekly']['hour'] AND $week == $cfg['cron_weekly']['weekday']) {
	// weekly account usage mailing
	
	// Run scheduled backups
	$pid = pcntl_fork();
	webcp_log(3,0,'webcp.php',"Note: Forking schedbackups.inc.phps",0,$echo);
	if ($pid == -1) {
		webcp_log(0,0,"webcp.php","Fork Error: could not fork webcp.php for schedbackups.php",0,$echo);
	} elseif (!$pid) {

		// Log Process ID
		$fp = fopen($cfg['pid'].'-backup',"w+");
		$mypid = getmypid();
		fwrite($fp,$mypid);
		fflush($fp);
		fclose($fp);

		// Set no timeout (unlimited)
		set_time_limit(0);
	
		$schedbackups = "Weekly";
		// include cron script and stay there
		include("cron/schedbackups.inc.phps");
		exit;
	}

	webcp_log(2,0,"cron","Weekly scheduled tasks ran",0);
}


//
// Run monthly tasks
if ($minute == $cfg['cron_monthly']['minute'] AND $hour == $cfg['cron_monthly']['hour'] AND $day == $cfg['cron_monthly']['day']) {
	// Clean up transfer used
	mysql_query("UPDATE domains SET transfer_used = 0");
	
	// Run scheduled backups
	$pid = pcntl_fork();
	webcp_log(3,0,'webcp.php',"Note: Forking schedbackups.inc.phps",0,$echo);
	if ($pid == -1) {
		webcp_log(0,0,"webcp.php","Fork Error: could not fork webcp.php for schedbackups.php",0,$echo);
	} elseif (!$pid) {

		// Log Process ID
		$fp = fopen($cfg['pid'].'-backup',"w+");
		$mypid = getmypid();
		fwrite($fp,$mypid);
		fflush($fp);
		fclose($fp);

		// Set no timeout (unlimited)
		set_time_limit(0);
	
		$schedbackups = "Monthly";
		// include cron script and stay there
		include("cron/schedbackups.inc.phps");
		exit;
	}

	webcp_log(2,0,"cron","Monthly scheduled tasks ran",0);
	
}


//
// Run minute tasks

// monitor system
include('cron/monitor.inc.phps');
// manage transfer table
// include('cron/transfer.inc.phps');

mysql_close();
?>
Return current item: web-cp - Web Hosting Control Panel