phpinfo()之间的区别是什么? 和PHP -i?

Search on DDG and in here didn't get any interesting results. I've heard they're different, but I want to know what makes them different and what advantage is there in having two different configurations ?

EDIT : Yes, I am running them both from the CLI.

phpinfo() is a language function that will display its output regardless of whether the script that it's executed in is called through the web SAPI or from CLI;

php -i is purely a command line switch to get information about PHP from the command line.

Why different configurations for web sapi and for CLI? Because you might have different requirements; often devs will run long command line scripts and don't want the web sapi timeout applied, similarly with memory settings; and max file/post size ini settings are meaningless for CLI, so why bother having them in the cli ini file when they're only needed for the web?

php -i gives you the same info you got using phpinfo() but:

  • can use a different set of INI files than your web server (so you can different values for some configuration parameters)
  • it formats the data in a console-friendly way (no html tags, for example)

Edit: don't digged the sources, but I can bet both uses the same code to extract their info .. in other words php -i is "calling phpinfo()" in a console-aware way and context

Depending on your server distribution, there may be separate php.ini files for the command line and web server.

Source:

Pro PHP Patterns, Frameworks, Testing and More By Kevin McArthur

https://books.google.pl/books?id=CpUhDavmgSMC&pg=PT410&lpg=PT410&dq=%22php+-i+command%22&source=bl&ots=iljmNZ96ZU&sig=iRrX8_UjJWiOzlLtRz0zwJOtQJc&hl=pl&sa=X&ved=0ahUKEwicoq6NrsLLAhVjQZoKHeSSA8wQ6AEIPDAE#v=onepage&q=%22php%20-i%22&f=false