Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created October 23, 2012 17:52
Show Gist options
  • Save al-the-x/3940331 to your computer and use it in GitHub Desktop.
Save al-the-x/3940331 to your computer and use it in GitHub Desktop.
Finding OPENSHIFT environment variables in PHP / Zend Server
<?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();
@al-the-x
Copy link
Author

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 the OPENSHIFT_* variables in $_ENV but none of the OPENSHIFT_DB_* variables... Looks like they're getting injected differently. :/

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