Browse Source

Before a database dump let's check if we can handle timeouts

Signed-off-by: emanuele <[email protected]>
emanuele 12 years ago
parent
commit
3ccb6819dd
1 changed files with 10 additions and 2 deletions
  1. 10 2
      Sources/ManageMaintenance.php

+ 10 - 2
Sources/ManageMaintenance.php

@@ -155,13 +155,21 @@ function MaintainDatabase()
 	// Here is more tricky: it depends on many factors, but the main idea is that
 	// if it takes "too long" the backup is not reliable. So, I know that on my computer it take
 	// 20 minutes to backup 2.5 GB, of course my computer is not representative, so I'll multiply by 4 the time.
-	// I would consider "too long" 5 minutes (I know it can be a long time, but let's start with that:
+	// I would consider "too long" 5 minutes (I know it can be a long time, but let's start with that):
 	// 80 minutes for a 2.5 GB and a 5 minutes limit means 160 MB approx
 	$plain_limit = 240000;
+	// Last thing: are we able to gain time?
+	$current_time_limit = ini_get('max_execution_time');
+	@set_time_limit(159); //something strange just to be sure
+	$new_time_limit = ini_get('max_execution_time');
 
 	$context['use_maintenance'] = 0;
 
-	if ($context['safe_mode_enable'])
+	// External tool if:
+	//  * safe_mode enable OR
+	//  * cannot change the execution time OR
+	//  * cannot reset timeout
+	if ($context['safe_mode_enable'] || empty($new_time_limit) || $current_time_limit == $new_time_limit || !function_exists('apache_reset_timeout'))
 		$context['suggested_method'] = 'use_external_tool';
 	elseif ($zip_limit < $plain_limit && $messages < $zip_limit)
 		$context['suggested_method'] = 'zipped_file';