1

For some of my running PHP-FPM web applications, I need to set up cronjobs. Currently they are using the CLI default php.ini.

Is there an easy way (e.g. script) to generate a new php.ini from the current environment?

I want to use those autogenerated php.ini files within cronjobs (like php -c /srv/foo/php.ini -f /srv/foo/cron.php)

Of course, I could do it by hand, copy the FPM default config and manually replace the overwritten values with the one's setup with the PHP-FPM pool configuration but that result in some weeks of copy&pasting.

burnersk
  • 2,056
  • 5
  • 27
  • 39

1 Answers1

1

You could write out a dynamic php.ini by running something like

<?php 
$s = array();
foreach(ini_get_all() as $k=>$v) {
     if ($v['local_value'] || $v['global_value']) {
        $s[] = sprintf("%s = %s", $k, $v['local_value']?$v['local_value']:$v['global_value']);
    }
}

file_put_contents("out.ini", join("\n", $s));
?>
Mark R.
  • 363
  • 1
  • 5