diff --git a/background_process.module b/background_process.module
index bfc553d..8348e43 100755
--- a/background_process.module
+++ b/background_process.module
@@ -40,6 +40,9 @@ if (!defined('HTTP_REQUEST_TIMEOUT')) {
 }

 // Ensure correct current directory during shutdown.
+if (!defined('DRUPAL_ROOT')) {
+  define('DRUPAL_ROOT', getcwd());
+}
 register_shutdown_function('_background_process_cwdfix');

 // ---------- HOOKS ----------
@@ -1282,7 +1285,7 @@ function _background_process_restart($process, $args = array()) {
  * Fix for current directory bug during shutdown
  */
 function _background_process_cwdfix() {
-  chdir(dirname($_SERVER['PHP_SELF']));
+  chdir(DRUPAL_ROOT);
 }

 /**
