Charlie Walton
Charlie Walton

Reputation: 312

How to read php.ini values at runtime?

I am writing a PHP library and to increase its portability and robustness I would like to be able to read the php.ini file to access the installation settings.

Is there a simple way to do this or do I need to do this the hard way and write code to parse this myself?

Thanks

Upvotes: 5

Views: 5344

Answers (2)

ZorleQ
ZorleQ

Reputation: 1427

PHP has a nice support for INI files. Along with the php_ini_loaded_file() you can get the details of current ini file.

<?php 

    // get path to the ini file
    $inipath = php_ini_loaded_file();

    // Parse with sections
    $ini_array = parse_ini_file($inipath , true);
    print_r($ini_array);

?>

http://php.net/manual/en/function.parse-ini-file.php

http://php.net/manual/en/function.php-ini-loaded-file.php

Upvotes: 6

BenM
BenM

Reputation: 53198

I doubt that you need all of the php.ini file. For specific values, why not use ini_get()? For example, to get the maximum post size, you can simply use:

$maxPostSize = ini_get('post_max_size');

Upvotes: 9

Related Questions