How to read php.ini values ​​at runtime?

I am writing a PHP library and increasing its portability and reliability. I would like to read the php.ini file to access the installation settings.

Is there an easy way to do this, or do I need to do it in a complicated way and write code to parse it myself?

thanks

+4
source share
2 answers

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

 $maxPostSize = ini_get('post_max_size'); 
+8
source

PHP has nice support for INI files. Along with php_ini_loaded_file() you can get information about the 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

+5
source

Source: https://habr.com/ru/post/1487246/


All Articles