Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What's the best way to read data from a bash configuration file (containing variable assignments) into php? Currently, my php data reads the required bash variables by assigning php variables via shell_exec. The bash code within the shell_exec statements greps for the appropriate values. An example might be: $myvar = shell_exec('grep myvar configfile.cfg | cut -d\" -f2'); However, it seems horribly inefficient to have to grep the entire configuration file for each php variable that I want to fetch. Since I'm relatively new at php, I know that there's GOT to be a better way to do this. Any suggestions?

share|improve this question
    
Learn how to properly open and read the file? fopen(), loop over file, reading each line, and parse out what you want. –  Zoredache Oct 17 '11 at 1:35
    
Or keep all vars you need as associative array in $_SESSION, so you need to read it only once per session. –  ott-- Oct 17 '11 at 2:57
add comment

1 Answer

While I would like to argue the reason why you need to do this in first place it should be a matter of reading the profile and extracting variable assignment in order to interpret these the way you want inside PHP.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.