Home > Article > Backend Development > PHP Server Environment Variable $_ENV_PHP Tutorial
PHP $_ENV variable
$_ENV is an array containing server-side environment variables. It is a super global variable in PHP and we can directly access it anywhere in the PHP program.
$_ENV just passively accepts server-side environment variables and converts them into array elements. You can try printing it directly:
print_r($_ENV);
Due to space limitations, the printed results are not listed here, and the printed results on different servers may be completely different.
$_ENV array element
The elements (array units) in the $_ENV array vary greatly depending on the server environment, so it is impossible to list a complete list like $_SERVER. The following are the more common elements contained in the $_ENV array:
$_SERVER['PATH']: environment variable PATH path.
$_SERVER['CLASSPATH']: System CLASSPATH path.
$_SERVER['LIB']: System LIB library path.
$_SERVER['INCLUDE']: System Include path. Note that it is different from PHP's include path.
$_SERVER['OS']: Operating system type.
$_SERVER['LANG']: system language, such as en_US or zh_CN.
$_SERVER['PWD']: Current working directory.
$_SERVER['TEMP']: System TEMP path.
$_SERVER['AP_PARENT_PID']: Current process ID number.
$_SERVER['NUMBER_OF_PROCESSORS']: Number of system CPUs.
Reasons why $_ENV is empty and solutions
If the printout $_ENV is empty, you can check the configuration of php.ini:
variables_order = "EGPCS"
The above configuration represents the source and order of external variables accepted by PHP. EGPCS is the abbreviation of Environment, Get, Post, Cookies and Server. If E is missing from the configuration of variables_order, PHP cannot accept environment variables, and $_ENV will be empty.
Original address: http://www.5idev.com/p-php_env.shtml