I need to return the path of folder configured via the --with-config-file-scan-dir switch for a particular PHP implementation.
I can achieve this by writing bash code something like:
folder=$(php --ini \
| grep "Scan for additional .ini files in:" \
| cut -d" " -f7 \
)
But the above approach seems inexact and potentially error prone.
My preference would be to do something like the following:
folder=$(php -r 'print ini_get("with-config-file-scan-dir config option");')
but I can't seem to find the necessary configuration option name.
I would greatly appreciate some guru input on this if you have it!
thanks in advance
You can use PHP_CONFIG_FILE_SCAN_DIR.
php -r "echo PHP_CONFIG_FILE_SCAN_DIR;"
Maybe this would help you? http://php.net/manual/en/function.php-ini-scanned-files.php
<?php
if ($filelist = php_ini_scanned_files()) {
if (strlen($filelist) > 0) {
$files = explode(',', $filelist);
foreach ($files as $file) {
echo "<li>" . trim($file) . "</li>
";
}
}
}
?>
Actually, the code above would print all the scanned files... If you just want the dir, maybe substr the first element found?
<?php
if ($filelist = php_ini_scanned_files()) {
if (strlen($filelist) > 0) {
$files = explode(',', $filelist);
$dir = substr($files[0],0,strrpos($files[0],"/")+1);
echo $dir;
}
}
?>
Check the return values of
php_ini_loaded_file()
or
php_ini_scanned_files()
Not shure what exactly you're looking for. The first one gives the path to the loaded php.ini file. The second one gets the paths and filenames for additional loaded config files. You might need to extra the directory names with dirname(). Might not be a one liner, but hope this helps.