5.2. PHP Configuration during Runtime
Checking and changing the settings of directives in php.ini directly is often a quick and easy solution to monitoring and modifying your installation, but many times you can't bring the server down to make a change, or you need to know a setting while a script is running. The techniques in this part of the chapter will help you make modifications while the server is still running.
5.2.1. Obtaining Current Runtime Settings
If you need to know the exact version of PHP installed, PHP provides the phpversion() function, which returns a string listing the full installed version. For example:
<?php echo "The current version of PHP installed is: " . phpversion(); ?>
This would output something like the following:
The current version of PHP installed is: 5.0.4
5.2.1.1. Retrieving Configuration Settings
There might be times when a simple version check isn't enough information, and you require a little more information about the way PHP is configured, but you don't have access to php.ini directly. To look up runtime configuration settings, you have three main choices: ini_get(), get_cfg_var(), and ini_get_all().
The first option, ini_get(), checks a given string against the current runtime configuration. If a setting matches, it returns the value of that setting; if no match is found, an empty string is returned:
<?php echo "Error reporting: " . ini_get('error_reporting') . "\n" . "Register globals: " . ini_get('register_globals') . "\n" . "Nonexistant ...
Get Professional LAMP: Linux®, Apache, MySQL®, and PHP5 Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.