diff --git a/modules/statistics/config-templates/module_statistics.php b/modules/statistics/config-templates/module_statistics.php
index 7b839148f924f822cea140625d0750c48e675a50..e684ccd1ab373a033a355d2b2a76f3737aa65d00 100644
--- a/modules/statistics/config-templates/module_statistics.php
+++ b/modules/statistics/config-templates/module_statistics.php
@@ -38,6 +38,14 @@ $config = array (
 	 *     'cron_tag' => NULL,
 	 */
 	'cron_tag' => 'daily',
+
+	/*
+	 * Set max running time for this script. This is also controlle by max_execution_time in php.ini
+	 * and is defalut set to 30 sec. Your web server can have other timeout configurations that may
+	 * also interrupt PHP execution. Apache has a Timeout directive and IIS has a
+	 * CGI timeout function. Both default to 300 seconds.
+	 */
+	'time_limit' => 300,
 	
 	'statrules' => array(
 		'sso_hoursday' => array(
diff --git a/modules/statistics/hooks/hook_cron.php b/modules/statistics/hooks/hook_cron.php
index 1847682d6c139e6ef30e1105d6ffcffb2f333ab2..1c4d43adc35c507f30e491efe1cf0ebf64292398 100644
--- a/modules/statistics/hooks/hook_cron.php
+++ b/modules/statistics/hooks/hook_cron.php
@@ -14,6 +14,11 @@ function statistics_hook_cron(&$croninfo) {
 	if (is_null($statconfig->getValue('cron_tag', NULL))) return;
 	if ($statconfig->getValue('cron_tag', NULL) !== $croninfo['tag']) return;
 	
+	$maxtime = $statconfig->getInteger('time_limit', NULL);
+	if($maxtime){
+		set_time_limit($maxtime);
+	}
+	
 	try {
 		$aggregator = new sspmod_statistics_Aggregator();
 		$results = $aggregator->aggregate();