Created
March 15, 2012 21:21
-
-
Save davidalexander/2047048 to your computer and use it in GitHub Desktop.
Thoughts on best way to test subdomain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* how best to turn on errors for staging subdomains | |
* | |
* as this is in the index.php, performance is important, | |
* although technically the page will be cached | |
*/ | |
// 1. preg_match | |
if (preg_match('/^s1\.|^s2\.|^s3\.|^s4\.|^s5\.|^mac\.|^local\.|^mac-upgrade\./', $_SERVER['HTTP_HOST'])) { | |
Mage::setIsDeveloperMode(true); | |
ini_set('display_errors', 1); | |
} | |
// 2. in_array | |
$staging_subdomains = array( | |
's1', | |
's2', | |
's3', | |
's4', | |
's5', | |
'mac', | |
'local', | |
'mac-upgrade', | |
); | |
list($subdomain) = explode('.', $_SERVER['HTTP_HOST'], 2); | |
if (in_array($subdomain,$staging_subdomains)) { | |
Mage::setIsDeveloperMode(true); | |
ini_set('display_errors', 1); | |
} | |
// 3. strpos - THE ONE WE'RE GOING FOR | |
$staging_subdomains = array( | |
's1', | |
's2', | |
's3', | |
's4', | |
's5', | |
'mac', | |
'local', | |
'mac-upgrade', | |
); | |
foreach ($staging_subdomains as $needle) { | |
if (strpos($_SERVER['HTTP_HOST'], $needle . '.') === 0) { | |
Mage::setIsDeveloperMode(true); | |
ini_set('display_errors', 1); | |
break; | |
} | |
} | |
// 4. remove strpos | |
$staging_subdomains = array( | |
's1', | |
's2', | |
's3', | |
's4', | |
's5', | |
'mac', | |
'local', | |
'mac-upgrade', | |
); | |
list($subdomain) = explode('.', $_SERVER['HTTP_HOST'], 2); | |
foreach ($staging_subdomains as $needle){ | |
if ($needle === $subdomain) { | |
Mage::setIsDeveloperMode(true); | |
ini_set('display_errors', 1); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version 2 benchmark http://codepad.viper-7.com/Isgmup