Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.925
diff -u -r1.925 common.inc
--- includes/common.inc	18 Jun 2009 21:19:01 -0000	1.925
+++ includes/common.inc	28 Jun 2009 19:23:00 -0000
@@ -2242,6 +2242,33 @@
 }
 
 /**
+ * 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
+ * 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
@@ -3364,10 +3391,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.219
diff -u -r1.219 locale.inc
--- includes/locale.inc	8 Jun 2009 05:00:11 -0000	1.219
+++ includes/locale.inc	28 Jun 2009 19:22:59 -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.1075
diff -u -r1.1075 node.module
--- modules/node/node.module	27 Jun 2009 18:19:41 -0000	1.1075
+++ modules/node/node.module	28 Jun 2009 19:22:58 -0000
@@ -2638,10 +2638,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.117
diff -u -r1.117 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	16 Jun 2009 04:43:47 -0000	1.117
+++ modules/simpletest/drupal_web_test_case.php	28 Jun 2009 18:36:26 -0000
@@ -1044,7 +1044,7 @@
     // Create the files directory.
     file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
 
-    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.28
diff -u -r1.28 run-tests.sh
--- scripts/run-tests.sh	10 Jun 2009 16:17:02 -0000	1.28
+++ scripts/run-tests.sh	28 Jun 2009 19:24:26 -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();
 

