Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read php.ini values at runtime?

Tags:

php

ini

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

like image 554
Charlie Walton Avatar asked Jun 20 '13 09:06

Charlie Walton


People also ask

What is the use of Ini_set ()?

The ini_set() function allows you to change system attributes that affect the way your script is executed. Changes only affect the current script, and will revert back when the script ends. To use ini_set() , pass it the value you want to change as its first parameter, and the new value to use as its second parameter.

Where can I find PHP ini file on server?

ini file: Whenever we install PHP, we can locate the configuration file inside the PHP folder. If using xampp, we can find the configuration file in one or many versions, inside the path '\xampp\php'. Note: Other versions of this file are php. ini-development and php.

How do I access PHP ini in WordPress?

If you're using WAMP for your local WordPress installation, you can easily find the location of php. ini by right-clicking on the program icon and navigating to PHP > php. ini. That's it.


2 Answers

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');
like image 199
BenM Avatar answered Oct 18 '22 15:10

BenM


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

like image 44
ZorleQ Avatar answered Oct 18 '22 13:10

ZorleQ