CRM-16373 - Bootstrap subsystems in more predictable order
[civicrm-core.git] / CRM / Core / Config / Runtime.php
index 95f4810d7235da242aa41f663bf54a89af6af3b1..bfaf7c08e651b79c3f62cd83654002cce4ed45c8 100644 (file)
@@ -195,4 +195,28 @@ class CRM_Core_Config_Runtime {
     exit();
   }
 
+  /**
+   * Create a unique identification code for this runtime.
+   *
+   * If two requests involve a different hostname, different
+   * port, different DSN, etc., then they should also have a
+   * different runtime ID.
+   *
+   * @return mixed
+   */
+  public static function getId() {
+    if (!isset(Civi::$statics[__CLASS__]['id'])) {
+      Civi::$statics[__CLASS__]['id'] = md5(implode(\CRM_Core_DAO::VALUE_SEPARATOR, array(
+        defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID : 1, // e.g. one database, multi URL
+        parse_url(CIVICRM_DSN, PHP_URL_PATH), // e.g. one codebase, multi database
+        \CRM_Utils_Array::value('SCRIPT_FILENAME', $_SERVER, ''), // e.g. CMS vs extern vs installer
+        \CRM_Utils_Array::value('HTTP_HOST', $_SERVER, ''), // e.g. name-based vhosts
+        \CRM_Utils_Array::value('SERVER_PORT', $_SERVER, ''), // e.g. port-based vhosts
+        // Depending on deployment arch, these signals *could* be redundant, but who cares?
+      )));
+    }
+    return Civi::$statics[__CLASS__]['id'];
+  }
+
+
 }