Skip to content

Instantly share code, notes, and snippets.

@davidalexander
Created March 15, 2012 21:21
Show Gist options
  • Save davidalexander/2047048 to your computer and use it in GitHub Desktop.
Save davidalexander/2047048 to your computer and use it in GitHub Desktop.
Thoughts on best way to test subdomain
<?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;
}
}
@Demoli
Copy link

Demoli commented Mar 16, 2012

Version 2 benchmark http://codepad.viper-7.com/Isgmup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment