phpconfigurationzend-server

php.ini different from php info (cli only)


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:


Solution

  • 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.