On the $config variable



  • Hi all. I am running few basic command on the PHP shell. I have few questions on the $config variable:

    1. How can I dump $config variable to a file using php?
    2. Which will be the format of the file that contains the content of the $config variable?  It is not php, it is not xml, so.. what is it?
    3. Would I be able to parse the content of the file with python?

    Thank you.


  • Rebel Alliance Developer Netgate

    Why would you want to do that?

    You can just parse /conf/config.xml direcly with XML functions in python if you're just interested in the values.  $config is just a PHP representation of the contents of config.xml.

    If you have to, you could dump it using something like

    file_put_contents("/root/somefile.txt", var_export($config, true));

    Which would be human and PHP readable.

    Or use serialize() for machine readable.

    But seriously… just read the XML directly. Don't bother adding more PHP to the mix.



  • Thank you for the answer. I will use the config.xml file to gether info on the configuration. My idea is to change the configuration file remotely, i.e. through Ansible, interacting with pfSense with php commands (no-web interface).


  • Rebel Alliance Developer Netgate

    That won't be quite so simple, lots of other gotchas there (the config.cache, reloading specific areas, etc).

    There are already threads about doing what you propose.



  • I'll try..Could you point me to one of those threads? thanks again