php.ini: which one?

Generally speaking, the cli/php.ini file is used when the PHP binary is called from the command-line.

You can check that running php --ini from the command-line.

fpm/php.ini will be used when PHP is run as FPM — which is the case with an nginx installation.

And you can check that calling phpinfo() from a php page served by your webserver.

cgi/php.ini, in your situation, will most likely not be used.

Using two distinct php.ini files (one for CLI, and the other one to serve pages from your webserver) is done quite often, and has one main advantages : it allows you to have different configuration values in each case.

Typically, in the php.ini file that’s used by the web-server, you’ll specify a rather short max_execution_time : web pages should be served fast, and if a page needs more than a few dozen seconds (30 seconds, by default), it’s probably because of a bug — and the page’s generation should be stopped.

On the other hand, you can have pretty long scripts launched from your crontab (or by hand), which means the php.ini file that will be used is the one in cli/. For those scripts, you’ll specify a much longer max_execution_time in cli/php.ini than you did in fpm/php.ini.

max_execution_time is a common example ; you could do the same with several other configuration directives, of course.

Leave a Comment