Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11708201
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/files/usr/local/lib/php-fpm-env/PhpFpmEnvironment.php b/files/usr/local/lib/php-fpm-env/PhpFpmEnvironment.php
index 31f4d1e..61788c5 100755
--- a/files/usr/local/lib/php-fpm-env/PhpFpmEnvironment.php
+++ b/files/usr/local/lib/php-fpm-env/PhpFpmEnvironment.php
@@ -1,77 +1,103 @@
#!/usr/bin/env php
<?php
/**
* Allows to get the content of a php-fpm environment configuration file
*/
class PhpFpmEnvironment {
/**
* The temporary directory, used in TMP, TEMP and TMPDIR environment variables
* @var string
*/
const TMP = '/tmp';
/**
* The path where to find executables, where sbin should be excluded if you don't run PHP as root.
* @var string
*/
const PATH = '/usr/local/bin:/usr/bin:/bin';
/**
* The environment variables to discard
* @var Array
*/
const VARIABLES_TO_DISCARD = [
'_', // The caller executable script, not pertinent
'HOME', // Set correctly by php-fpm
'TERM', // Not pertinent in server context
'MYSQL_ENV_MYSQL_ROOT_PASSWORD', // from --link …:mysql
];
/**
* Gets an environment array from the current process environment,
* with PATH and temp variablesfiltered.
*
* @return Array
*/
public static function getEnvironmentVariables () {
$variables = [];
foreach ($_ENV as $key => $value) {
- if (static::mustIgnoreVariable($key)) {
- continue;
+ if (!static::mustIgnoreVariable($key)) {
+ $variables[$key] = $value;
}
-
- $variables[$key] = $value;
}
- $variables['PATH'] = static::PATH;
+ static::addHardcodedEnvironmentVariables($variables);
+
+ return $variables;
+ }
+
+ /**
+ * Adds hardcoded and always wanted environment variables
+ * (path, temporary directory) to the specified array.
+ *
+ * @paran array $variables the array to add the variables to
+ */
+ public static function addHardcodedEnvironmentVariables (&$variables) {
+ static::addTempEnvironmentVariables ($variables);
+ static::addPathEnvironmentVariables ($variables);
+ }
+
+ /**
+ * Adds temporary directory environment variables to the specified array.
+ *
+ * @paran array $variables the array to add the variables to
+ */
+ public static function addTempEnvironmentVariables (&$variables) {
$variables['TMP'] = static::TMP;
$variables['TEMP'] = static::TMP;
$variables['TMPDIR'] = static::TMP;
+ }
- return $variables;
+ /**
+ * Adds temporary directory environment variables to the specified array.
+ *
+ * @paran array $variables the array to add the variables to
+ */
+ public static function addPathEnvironmentVariables (&$variables) {
+ $variables['PATH'] = static::PATH;
}
/**
* Determines if the variable name must be ignored
*
* @return bool true if the variable must be ignored; otherwise, false.
*/
public static function mustIgnoreVariable ($variableName) {
return in_array($variableName, static::VARIABLES_TO_DISCARD);
}
/**
* Prints the environment
*/
public static function printConfig () {
$variables = static::getEnvironmentVariables();
foreach ($variables as $key => $value) {
echo 'env["', $key, '"] = "', $value, '"', PHP_EOL;
}
}
}
PhpFpmEnvironment::printConfig();
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Sep 15, 05:11 (14 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2983615
Default Alt Text
(3 KB)
Attached To
Mode
rDPHPFPM Docker image for Nginx, php-fpm
Attached
Detach File
Event Timeline
Log In to Comment