What is the difference between phpinfo(); and php -i?

血红的双手。 提交于 2019-12-11 12:56:07

问题


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.


回答1:


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?




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/36006945/what-is-the-difference-between-phpinfo-and-php-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!