create arbitrary values in php.ini

2019-02-22 06:54发布

问题:

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

回答1:

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



回答2:

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()