Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.888
diff -u -r1.888 common.inc
--- includes/common.inc	27 Apr 2009 20:19:35 -0000	1.888
+++ includes/common.inc	1 May 2009 13:28:47 -0000
@@ -1931,6 +1931,27 @@
 }
 
 /**
+ * Attempt to increase the PHP maximum execution time.
+ *
+ * A wrapper around PHP's set_time_limit(). To avoid PHP warnings it checks if
+ * PHP is not running in 'safe_mode' and if the function is not disabled
+ * (through php.ini or Suhosin).
+ *
+ * @param $time_limit
+ *   An integer specifying the new time limit, in seconds. A value of 0
+ *   indicates unlimited execution time.
+ */
+function drupal_increase_time_limit($time_limit) {
+  // ini_get will get either boolean value or literal string depending of the
+  // context. So we have to check both cases.
+  $safe_mode = ini_get('safe_mode');
+  $safe_mode = $safe_mode == 1 || strtolower($safe_mode) == 'on';
+  if (!$safe_mode && function_exists('set_time_limit') && strpos(ini_get('suhosin.executor.func.blacklist'), 'set_time_limit') === FALSE) {
+    set_time_limit($time_limit);
+  }
+}
+
+/**
  * Returns the path to a system item (module, theme, etc.).
  *
  * @param $type
@@ -3091,8 +3112,8 @@
   // Allow execution to continue even if the request gets canceled.
   @ignore_user_abort(TRUE);
 
-  // Increase the maximum execution time.
-  @set_time_limit(240);
+  // Try to increase the maximum execution time.
+  drupal_increase_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.214
diff -u -r1.214 locale.inc
--- includes/locale.inc	27 Apr 2009 20:19:35 -0000	1.214
+++ includes/locale.inc	1 May 2009 13:23:17 -0000
@@ -1165,10 +1165,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 increase the maximum execution time.
+  drupal_increase_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.1043
diff -u -r1.1043 node.module
--- modules/node/node.module	29 Apr 2009 17:48:11 -0000	1.1043
+++ modules/node/node.module	1 May 2009 13:23:16 -0000
@@ -2715,10 +2715,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 increase the maximum execution time.
+      drupal_increase_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.101
diff -u -r1.101 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	29 Apr 2009 21:35:38 -0000	1.101
+++ modules/simpletest/drupal_web_test_case.php	1 May 2009 13:23:02 -0000
@@ -907,7 +907,7 @@
     // Create the files directory.
     file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
 
-    set_time_limit($this->timeLimit);
+    drupal_increase_time_limit($this->timeLimit);
   }
 
   /**
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.36
diff -u -r1.36 common.test
--- modules/simpletest/tests/common.test	27 Apr 2009 20:19:38 -0000	1.36
+++ modules/simpletest/tests/common.test	1 May 2009 13:23:00 -0000
@@ -967,3 +967,31 @@
   }
 }
 
+/**
+ * Test increasing PHP's maximum execution time.
+ *
+ * Note that these tests will fail if the server environment is not appropriate,
+ * i.e. if safe_mode is on, or if PHP's set_time_limit() is disabled.
+ *
+ * Also note that drupal_increase_time_limit() doesn't do any checking on the validity
+ * of the supplied $time_limit, so we don't test that here.  
+ */
+class CommonTimeLimitTestCase extends DrupalWebTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('Set PHP maximum execution time'),
+      'description' => t('Test increasing the PHP time limit. Requires safe_mode off, and PHP's set_time_limit() not disabled.'),
+      'group' => t('System'),
+    );
+  }
+
+  function testSetTimeLimit() {
+    // Check we can increase the time limit.
+    drupal_increase_time_limit(101);
+    $this->assertEqual(ini_get('max_execution_time'), 101, t('Check time limit can be increased.'));
+
+    // Check we can set the time limit to 0 (unlimited).
+    drupal_increase_time_limit(0);
+    $this->assertEqual(ini_get('max_execution_time'), 0, t('Check time limit can be set to unlimited.'));
+  }
+}
Index: scripts/run-tests.sh
===================================================================
RCS file: /cvs/drupal/drupal/scripts/run-tests.sh,v
retrieving revision 1.26
diff -u -r1.26 run-tests.sh
--- scripts/run-tests.sh	13 Apr 2009 12:23:26 -0000	1.26
+++ scripts/run-tests.sh	1 May 2009 13:23:05 -0000
@@ -63,10 +63,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 unlimited execution time.
+drupal_increase_time_limit(0);
 
 simpletest_script_reporter_init();
 

