Articles in Configuration Category

Changing php.ini Settings at Runtime

PHP allows to change some settings mentioned in php.ini for the current script via ini_set(). This function requires two string arguments. First one is the setting name and the second one is the value.

For an example think that your script is in a remote server and it has disabled display_errors setting. If you are still developing your application and would like to see errors in web browser then you can enable this setting as below.

ini_set('display_errors', '1');

You may put above statement at the top of your script so that the setting will be enabled till the end of the script.

Values you set via ini_set() are applicable only to current script. Thereafter PHP would continue to use original values from php.ini.

Before changing a setting via ini_set(), you would need to identify whether PHP allows to change the particular setting via ini_set(). In PHP manual, it lists all the available settings in php.ini.

In this list there is a column called Changeable. According to definitions of the values in this column, you can only change the settings mentioned as PHP_INI_USER or PHP_INI_ALL.


This function accepts a setting name as the argument and returns its current value. If you placed this function after ini_set(), you would notice that it returns the newly assigned value (not the original php.ini value).


This function is similar to ini_get(). Difference is it returns the original value in php.ini even after an ini_set(). To illustrate this, make sure you have enabled display_errors in your php.ini and run following script.


ini_set('display_errors', '0');

echo ini_get('display_errors');
echo '<br />';
echo get_cfg_var('display_errors');


You would see the output as below.



This function instructs the PHP interpreter which type of errors should be reported for current script. For an example, to make sure all the errors are reported for current script, you can call this function at the top of your script as below.


Following statement would turn off all error reporting for the current script.


And following will enable all error reporting for the current script.


error_reporting() is a special function to change the error_reporting setting. It’s also possible to do the changes via ini_set(). For an example, following would enable reporting of all errors in current script (similar to error_reporting(E_ALL)).

ini_set('error_reporting', E_ALL);
Where to Head from Here...
Share with Your Peers...

We Value Your Feedback...

We love to hear what you think about this article. Please provide your opinion, suggestions and improvements using following form. Note that submitted feedback is not displayed but we will get back to you if it needs a reply.