Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.951
diff -u -r1.951 common.inc
--- includes/common.inc	31 Jul 2009 19:56:09 -0000	1.951
+++ includes/common.inc	3 Aug 2009 15:03:35 -0000
@@ -2295,6 +2295,35 @@
 }
 
 /**
+ * Attempts to set the PHP maximum execution time.
+ *
+ * Wrapper around the PHP function set_time_limit(). When called,
+ * set_time_limit() restarts the timeout counter from zero. In other words, 
+ * if the timeout is the default 30 seconds, and 25 seconds into script
+ * execution a call such as set_time_limit(20) is made, the script will run for
+ * a total of 45 seconds before timing out.
+ * 
+ * It also means that, unless we monitor the time spent running the current
+ * script, it is not possible to reliably prevent this function to decrease
+ * the time limit set by default or manually at the beginning of the script.
+ * 
+ * Before calling set_time_limit, we check if this function is available
+ * because it could be disabled by the server administrator. We also hide all
+ * the errors that could occur when calling set_time_limit because it is not
+ * possible to reliably ensure that PHP or a security PHP extension will not
+ * issue a warning error when preventing the use of this function.
+ *
+ * @param $time_limit
+ *   An integer specifying the new time limit, in seconds. A value of 0
+ *   indicates unlimited execution time.
+ */
+function drupal_set_time_limit($time_limit) {
+  if (function_exists('set_time_limit')) {
+    @set_time_limit($time_limit);
+  }
+}
+
+/**
  * Returns the path to a system item (module, theme, etc.).
  *
  * @param $type
@@ -3555,10 +3584,8 @@
   // Allow execution to continue even if the request gets canceled.
   @ignore_user_abort(TRUE);
 
-  // Try to increase the maximum execution time if it is too low.
-  if (ini_get('max_execution_time') < 240) {
-    @set_time_limit(240);
-  }
+  // Try to restart the timeout counter from zero and set a sufficient new time limit.
+  drupal_set_time_limit(240);
 
   // Fetch the cron semaphore
   $semaphore = variable_get('cron_semaphore', FALSE);
Index: includes/locale.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/locale.inc,v
retrieving revision 1.221
diff -u -r1.221 locale.inc
--- includes/locale.inc	30 Jul 2009 08:40:22 -0000	1.221
+++ includes/locale.inc	3 Aug 2009 15:03:35 -0000
@@ -1167,10 +1167,8 @@
  *   Text group to import PO file into (eg. 'default' for interface translations)
  */
 function _locale_import_po($file, $langcode, $mode, $group = NULL) {
-  // If not in 'safe mode', increase the maximum execution time.
-  if (!ini_get('safe_mode')) {
-    set_time_limit(240);
-  }
+  // Try to restart the timeout counter from zero and set a sufficient new time limit.
+  drupal_set_time_limit(240);
 
   // Check if we have the language already in the database.
   if (!db_query("SELECT COUNT(language) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) {
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.1090
diff -u -r1.1090 node.module
--- modules/node/node.module	31 Jul 2009 19:01:02 -0000	1.1090
+++ modules/node/node.module	3 Aug 2009 15:03:35 -0000
@@ -2646,10 +2646,9 @@
       batch_set($batch);
     }
     else {
-      // If not in 'safe mode', increase the maximum execution time.
-      if (!ini_get('safe_mode')) {
-        set_time_limit(240);
-      }
+      // Try to restart the timeout counter from zero and set a sufficient new time limit.
+      drupal_set_time_limit(240);
+
       $nids = db_query("SELECT nid FROM {node}")->fetchCol();
       foreach ($nids as $nid) {
         $node = node_load($nid, NULL, TRUE);
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.132
diff -u -r1.132 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	30 Jul 2009 10:46:53 -0000	1.132
+++ modules/simpletest/drupal_web_test_case.php	3 Aug 2009 15:03:35 -0000
@@ -1110,7 +1110,7 @@
     // directory will have been created already.
     variable_set('file_directory_path', $directory);
 
-    set_time_limit($this->timeLimit);
+    drupal_set_time_limit($this->timeLimit);
   }
 
   /**
Index: scripts/run-tests.sh
===================================================================
RCS file: /cvs/drupal/drupal/scripts/run-tests.sh,v
retrieving revision 1.32
diff -u -r1.32 run-tests.sh
--- scripts/run-tests.sh	30 Jul 2009 10:46:53 -0000	1.32
+++ scripts/run-tests.sh	3 Aug 2009 15:03:36 -0000
@@ -70,10 +70,8 @@
 
 $test_list = simpletest_script_get_test_list();
 
-// If not in 'safe mode', increase the maximum execution time.
-if (!ini_get('safe_mode')) {
-  set_time_limit(0);
-}
+// Try to set an unlimited execution time 
+drupal_set_time_limit(0);
 
 simpletest_script_reporter_init();
 

