I would like to put some of my app config data in php.ini
I tried just to add new values there and then get them with ini_get
I get nothing displayed.
Do I need to define new entries in an extension?
I know I can create a config file/ini file and easily parse it with PHP, But I want to avoid that.
I do that as I assume it is being loaded once per process.
I do not give here the big big picture, as I want to keep it as much as possible only a technical question, sadly, this platform does not allow debates.
I do need it inside the php.ini
Asked
Active
Viewed 3,868 times
7

Itay Moav -Malimovka
- 52,579
- 61
- 190
- 278
-
3You really should consider keeping your app configuration out of PHP.ini. PHP.ini should be just for PHP and its extensions, nothing more. Put your app configuration in a separate file. The loading penalty for this isn't something that will really slow you down. In addition, you can code this config file in PHP, which is convenient. – Brad Jun 16 '11 at 16:30
-
See http://stackoverflow.com/questions/5052558/declaring-global-variable-with-php-ini – Déjà vu Oct 07 '12 at 11:18
2 Answers
9
Have you looked at get_cfg_var( config_var )
?
http://www.php.net/manual/en/function.get-cfg-var.php
I believe this is for retrieving custom variables from e.g. the servers php.ini file

Mads Ohm Larsen
- 3,315
- 3
- 20
- 22
-
`get_cfg_var()` does the same as `ini_get()`, the only difference being `get_cfg_var` gets the value from the *php.ini* file, while `ini_get` gets the current value that may have been modified at runtime. Why would that answer the question? – Déjà vu Oct 07 '12 at 11:01
-
@ring0 `get_cfg_var()` doesn't do the exact same thing as `ini_get()`. Not sure why, but `ini_get()` doesn't actually get the value in `php.ini`, whereas `get_cfg_var()` does – Ascherer Jun 11 '13 at 17:09
-
1@ringø `ini_get()` retrieves the value of ini settings associated with registered modules, the values of which can be modified by a php.ini file. `get_cfg_var()` retrieves an ini value as it appears in the ini file. If a module defines an ini entry `mod.a` and this is set with the value 5 in a php.ini file, both functions would be likely to return 5 if the module is installed. If the module is not installed, `ini_get()` would return false whereas `get_cfg_var()` would still return 5. – Nick Mar 27 '16 at 14:10
0
Don't use php.ini to configure your application, it's not the right place (as the name says, it's intended to configure php, not any application using it).
If you want to use ini files for your application's configuration, have a look at parse_ini_file()

Lepidosteus
- 11,779
- 4
- 39
- 51
-
I understand but while it may not be a strict answer to your question, this is how you should actually do it; doing this in php.ini WILL ause you troubles at some point, be it migration or something else. If you are worried by performances as your question suggest, remember that if every request access that ini file it will end up in your file cache anyway, so this really won't be an issue. If you really really are sure this is your problem, use a in-memory cache (whatever php opcode cache system you use [APC, Xcache, ...] includes one). – Lepidosteus Jun 16 '11 at 16:45
-
I did not give the big big picture, as it is a lot of text, I kept it strictly technical question. I do need it to be in the php.ini – Itay Moav -Malimovka Jun 16 '11 at 16:55