PHP: ini_get_all - Manual (original) (raw)

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

ini_get_all — Gets all configuration options

Description

Parameters

extension

An optional extension name. If not [null](reserved.constants.php#constant.null) or the string core, the function returns only options specific for that extension.

details

Retrieve details settings or only the current value for each setting. Default is [true](reserved.constants.php#constant.true) (retrieve details).

Return Values

Returns an associative array with directive name as the array key. Returns [false](reserved.constants.php#constant.false) and raises an [E_WARNING](errorfunc.constants.php#constant.e-warning) level error if the extension doesn't exist.

When details is [true](reserved.constants.php#constant.true) (default) the array will contain global_value (set inphp.ini), local_value (perhaps set withini_set() or .htaccess), andaccess (the access level).

When details is [false](reserved.constants.php#constant.false) the value will be the current value of the option.

See the manual section for information on what access levels mean.

Note:

It's possible for a directive to have multiple access levels, which is why access shows the appropriate bitmask values.

Examples

Example #1 ini_get_all() examples

<?php print_r(ini_get_all("pcre")); print_r(ini_get_all()); ?>

The above example will output something similar to:

Array ( [pcre.backtrack_limit] => Array ( [global_value] => 100000 [local_value] => 100000 [access] => 7 )

[pcre.recursion_limit] => Array
    (
        [global_value] => 100000
        [local_value] => 100000
        [access] => 7
    )

) Array ( [allow_call_time_pass_reference] => Array ( [global_value] => 0 [local_value] => 0 [access] => 6 )

[allow_url_fopen] => Array
    (
        [global_value] => 1
        [local_value] => 1
        [access] => 4
    )

...

)

Example #2 Disabling details

<?php print_r(ini_get_all("pcre", false)); // Added in PHP 5.3.0 print_r(ini_get_all(null, false)); // Added in PHP 5.3.0 ?>

The above example will output something similar to:

Array ( [pcre.backtrack_limit] => 100000 [pcre.recursion_limit] => 100000 ) Array ( [allow_call_time_pass_reference] => 0 [allow_url_fopen] => 1 ... )

Notes

Note:

ini_get_all() ignores "array" ini options such aspdo.dsn.*.

See Also

Found A Problem?

justd@ntmailme

22 years ago

I guess the third entry is the required access level (to change this variable at runtime):

Constant           Value      Meaning 
PHP_INI_USER      1          Entry can be set in user scripts 
PHP_INI_PERDIR    2          Entry can be set in php.ini, .htaccess or httpd.conf  
PHP_INI_SYSTEM    4          Entry can be set in php.ini or httpd.conf  
PHP_INI_ALL       7          Entry can be set anywhere 

See also the docs for ini_set()

Hugo.

pmdumuid at gmail dot com

9 years ago

echo recreate_php_ini();

/**
  * Sample function to re-create a php ini config file.
  *
  * @return string
  */
function recreate_php_ini() {
    $a = ini_get_all();

    $data = [];
    foreach (array_keys($a) as $k) {
        <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>s</mi><mo>=</mo><mi>s</mi><mi>p</mi><mi>l</mi><mi>i</mi><mi>t</mi><mo stretchy="false">(</mo><mi mathvariant="normal">&quot;</mi><mover accent="true"><mi mathvariant="normal">&quot;</mi><mo>˙</mo></mover><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">ss = split(&quot;\.&quot;, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">ss</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.1813em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.01968em;">pl</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mopen">(</span><span class="mord">&quot;</span><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9313em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord">&quot;</span></span><span style="top:-3.2634em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.1389em;"><span class="mord">˙</span></span></span></span></span></span></span><span class="mpunct">,</span></span></span></span>k);
        if (count($ss) == 1) {
            $sec = "PHP";
            <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>v</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">v = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>k;
        } else {
            <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>e</mi><mi>c</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">sec = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">sec</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>ss[0];
            <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>v</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">v = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>ss[1];
        }
        <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi><mo stretchy="false">[</mo></mrow><annotation encoding="application/x-tex">data[</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mopen">[</span></span></span></span>sec][$v] = <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mo stretchy="false">[</mo></mrow><annotation encoding="application/x-tex">a[</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">a</span><span class="mopen">[</span></span></span></span>k]['global_value'];
    }
    ksort($data);
    $out = "";
    foreach ($data as <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>e</mi><mi>c</mi><mo>=</mo><mo>&gt;</mo></mrow><annotation encoding="application/x-tex">sec =&gt; </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">sec</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=&gt;</span></span></span></span>data) {
        <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>o</mi><mi>u</mi><mi>t</mi><mi mathvariant="normal">.</mi><mo>=</mo><mi mathvariant="normal">&quot;</mi><mo stretchy="false">[</mo></mrow><annotation encoding="application/x-tex">out .= &quot;[</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6151em;"></span><span class="mord mathnormal">o</span><span class="mord mathnormal">u</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">&quot;</span><span class="mopen">[</span></span></span></span>sec]\n";
        ksort($data);
        foreach ($data as <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mo>=</mo><mo>&gt;</mo></mrow><annotation encoding="application/x-tex">k =&gt; </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7335em;vertical-align:-0.0391em;"></span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=&gt;</span></span></span></span>v) {
            if (is_numeric($v)) {
                <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>o</mi><mi>u</mi><mi>t</mi><mi mathvariant="normal">.</mi><mo>=</mo><mi>s</mi><mi>p</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>t</mi><mi>f</mi><mo stretchy="false">(</mo><mi mathvariant="normal">&quot;</mi></mrow><annotation encoding="application/x-tex">out .= sprintf(&quot;%-40s = %s\n&quot;, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6151em;"></span><span class="mord mathnormal">o</span><span class="mord mathnormal">u</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">in</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord">&quot;</span></span></span></span>k, $v);
            } else {
                <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>o</mi><mi>u</mi><mi>t</mi><mi mathvariant="normal">.</mi><mo>=</mo><mi>s</mi><mi>p</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>t</mi><mi>f</mi><mo stretchy="false">(</mo><mi mathvariant="normal">&quot;</mi></mrow><annotation encoding="application/x-tex">out .= sprintf(&quot;%-40s = \&quot;%s\&quot;\n&quot;, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6151em;"></span><span class="mord mathnormal">o</span><span class="mord mathnormal">u</span><span class="mord mathnormal">t</span><span class="mord">.</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">in</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord">&quot;</span></span></span></span>k, $v);
            }
        }
        $out .= "\n";
    }
    return $out;
}

Julien MOREAU aka PixEye

7 years ago

If you want to load and parse your own ini file, have a look at parse_ini_file() function. Example:

<?php
// ... <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>m</mi><msub><mi>y</mi><mi>d</mi></msub><mi>a</mi><mi>t</mi><mi>a</mi><mo>=</mo><mi>p</mi><mi>a</mi><mi>r</mi><mi>s</mi><msub><mi>e</mi><mi>i</mi></msub><mi>n</mi><msub><mi>i</mi><mi>f</mi></msub><mi>i</mi><mi>l</mi><mi>e</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">my_data = parse_ini_file(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8095em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">m</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">d</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.0361em;vertical-align:-0.2861em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal">a</span><span class="mord mathnormal">rs</span><span class="mord"><span class="mord mathnormal">e</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">n</span><span class="mord"><span class="mord mathnormal">i</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.10764em;">f</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mopen">(</span></span></span></span>my_file, true);

peter at peteraba dot com

10 years ago

You can use the following snippet on servers to grab the live/staging configs in order to be able to replicate those in your development environment. (I use `php -a` for this)
 <?php
foreach (ini_get_all(null, false) as <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mi>e</mi><mi>y</mi><mo>=</mo><mo>&gt;</mo></mrow><annotation encoding="application/x-tex">key =&gt; </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03148em;">k</span><span class="mord mathnormal" style="margin-right:0.03588em;">ey</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=&gt;</span></span></span></span>value) echo "$key=$value;\n";
?>

root at mantoru dot de

17 years ago

Since a certain PHP version (I think it's 5.2.5) it is no longer possible to override INI entrys set with php_admin_* in httpd.conf. The access level will be set to 4 (PHP_INI_SYSTEM), which is also returned by this function.

The constants mentioned below are available in PHP, but without the prefix (e.g. INI_USER, INI_PERDIR).