Created
October 23, 2012 17:52
-
-
Save al-the-x/3940331 to your computer and use it in GitHub Desktop.
Finding OPENSHIFT environment variables in PHP / Zend Server
This file contains hidden or 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 | |
$find_openshift_db = function($variables){ | |
$keys = array_filter(array_keys($variables), function($key){ | |
return (strpos($key, 'OPENSHIFT') === 0); | |
}); | |
return array_intersect_key($variables, array_flip($keys)); | |
}; | |
?> | |
<h1> In <code>$_SERVER</code>? </h1> | |
<?php if ( $found = $find_openshift_db($_SERVER)): ?> | |
<pre><?php var_dump($found)?></pre> | |
<?php else: ?> | |
<p> Not here... :/ </p> | |
<?php endif; ?> | |
<h1> In <code>$_ENV</code>? </h1> | |
<?php if ( $found = $find_openshift_db($_ENV)): ?> | |
<pre><?php var_dump($found)?></pre> | |
<?php else: ?> | |
<p> Not here, either! O_O </p> | |
<?php endif; ?> | |
<?php if ( PHP_SAPI != 'cli' ) phpinfo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this through the PHP command-line and through Apache, and you'll get two different results. The
OPENSHIFT_DB_*
variables are set in your local environment, so they show up when you run through CLI. The Apache / Zend Server version has all theOPENSHIFT_*
variables in$_ENV
but none of theOPENSHIFT_DB_*
variables... Looks like they're getting injected differently. :/