php.ini different from php info (cli only)

1.3k Views Asked by At

I wrote a script to gather certain configuration data from our servers to compare different environments. For this I get the PHP settings using php -i command.

I noticed now that the output of 'php -i' does not show the same values as inside the loaded php.ini file.

# /usr/local/zend/bin/php -c /usr/local/zend/etc/php.ini -i | grep -E -e 'Configuration File|max_exec'

Configuration File (php.ini) Path => /usr/local/zend/etc
Loaded Configuration File => /usr/local/zend/etc/php.ini
max_execution_time => 0 => 0

# cat /usr/local/zend/etc/php.ini | grep max_exec
max_execution_time=1200

Note that this is php CLI only, there is no server involved. I verified the following things:

  • there are other .ini files scanned but none of them contains the max_execution_time directive.
  • php -i does not report a syntax error inside the php.ini (as other questions mentioned as a possible problem)
2

There are 2 best solutions below

0
rickdenhaan On BEST ANSWER

You cannot set max_execution_time for CLI. See the manual, in the section "Overridden php.ini directives":

PHP in a shell environment tends to be used for a much more diverse range of purposes than typical Web-based scripts, and as these can be very long-running, the maximum execution time is set to unlimited.

In other words, no matter what you set for max_execution_time in php.ini, CLI wil override it to be unlimited.

If you want to limit the execution time for a script, you can use the set_time_limit() function in your script itself.

0
Kep On

The docs state that

When running PHP from the command line the default setting is 0.

I don't think this setting has any meaning in CLI and isn't read from php.ini.

For clarification: You can still ini_set it and the CLI will behave accordingly, it just doesn't seem to get read from the php.ini file.