简体   繁体   English

了解管道:PHP -c

[英]Understanding piping: PHP -c

I am having trouble understanding this Linux command: 我在理解此Linux命令时遇到了麻烦:
php -r "readfile('https://getcomposer.org/installer');" | php -c php.ini

It appears the first part php -r is piping to php -c . 看来php -r的第一部分是管道到php -c But it appears php.ini is being read . 但是似乎正在读取 php.ini

Where can I find out more about php command options and they mean (-v and -c), and thus find out what the command is doing? 在哪里可以找到有关php命令选项的更多信息,它们的含义(-v和-c),从而了解该命令在做什么?

From man php : man php

OPTIONS --interactive -a Run PHP interactively. 选项--interactive -a交互运行PHP。 This lets you enter snippets of PHP code that directly get executed. 这使您可以输入直接执行的PHP代码段。 When readline sup‐ port is enabled you can edit the lines and also have history support. 启用readline支持后,您可以编辑行并具有历史记录支持。

  --bindpath address:port|port -b address:port|port Bind Path for external FASTCGI Server mode (CGI only). --no-chdir -C Do not chdir to the script's directory (CGI only). --no-header -q Quiet-mode. Suppress HTTP header output (CGI only). --timing count -T count Measure execution time of script repeated count times (CGI only). --php-ini path|file -c path|file Look for php.ini file in the directory path or use the specified file --no-php-ini -n No php.ini file will be used --define foo[=bar] -d foo[=bar] Define INI entry foo with value bar -e Generate extended information for debugger/profiler --file file -f file Parse and execute file --help -h This help --hide-args -H Hide script name (file) and parameters (args...) from external tools. For example you may want to use this when a php script is started as a daemon and the command line contains sensitive data such as passwords. --info -i PHP information and configuration --syntax-check -l Syntax check only (lint) --modules -m Show compiled in modules --run code -r code Run PHP code without using script tags '<?..?>' --process-begin code -B begin_code Run PHP begin_code before processing input lines --process-code code -R code Run PHP code for every input line --process-file file -F file Parse and execute file for every input line --process-end code -E end_code Run PHP end_code after processing all input lines --syntax-highlight -s Output HTML syntax highlighted source --server addr:port -S addr:port Start built-in web server on the given local address and port --docroot docroot -t docroot Specify the document root to be used by the built-in web server --version -v Version number --strip -w Output source with stripped comments and whitespace --zend-extension file -z file Load Zend extension file args... Arguments passed to script. Use '--' args when first argument starts with '-' or script is read from stdin --rfunction name --rf name Shows information about function name --rclass name --rc name Shows information about class name --rextension name --re name Shows information about extension name --rzendextension name --rz name Shows information about Zend extension name --rextinfo name --ri name Shows configuration for extension name --ini Show configuration file names 

From php.net: 从php.net:

Usage: php [options] [-f] [--] [args...] php [options] -r [--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -- [args...]
php [options] -a
用法:php [options] [-f] [-] [args ...] php [options] -r [--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -- [args...]
php [options] -a
[--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -- [args...]
php [options] -a

-a Run interactively -c | -a交互式运行-c | Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f 在此目录中查找php.ini文件-n将不使用php.ini文件-d foo [= bar]定义INI条目foo,值为'bar'-e生成调试器/探查器的扩展信息-f
Parse and execute . 解析并执行。 -h This help -i -h此帮助-i
PHP information -l Syntax check only (lint) -m PHP信息-l仅语法检查(lint)-m
Show compiled in modules -r Run PHP without using script tags -B Run PHP before processing input lines -R Run PHP for every input line -F Parse and execute for every input line -E Run PHP after processing all input lines -H Hide any passed arguments from external tools. 显示在模块中编译的代码-r在不使用脚本标签的情况下运行PHP -B在处理输入行之前运行PHP -R在每个输入行运行PHP -F解析并在每个输入行执行-E在处理所有输入行之后运行PHP -H隐藏任何从外部工具传递的参数。 -S : Run with built-in web server. -S:与内置的Web服务器一起运行。 -t Specify document root for built-in web server. -t指定内置Web服务器的文档根目录。 -s -s
Output HTML syntax highlighted source. 输出HTML语法突出显示的源。 -v Version number -w Output source with stripped comments and whitespace. -v版本号-w带注释和空格的输出源。 -z Load Zend extension . -z加载Zend扩展名。

args... Arguments passed to script. args ...参数传递给脚本。 Use -- args when first argument starts with - or script is read from stdin 当第一个参数以-开头或从stdin中读取脚本时,请使用-args

--ini Show configuration file names --ini显示配置文件名称

--rf Show information about function . -rf显示有关function的信息。 --rc Show information about class . --rc显示有关class的信息。 --re - 回覆
Show information about extension . 显示有关扩展名的信息。 --rz Show information about Zend extension . --rz显示有关Zend扩展名的信息。 --ri Show configuration for extension . --ri显示扩展的配置。

Edit:

php -r "readfile('https://getcomposer.org/installer');" | php -c php.ini 

This command runs the file https://getcomposer.org/installer using php.ini in the current directory as the config file. 此命令使用当前目录中的php.ini作为配置文件运行文件https://getcomposer.org/installer The same can be achieved with 可以用

php -r "require('https://getcomposer.org/installer');" -c php.ini

Running php with the -c option simply tells it where to find its configuration file. 使用-c选项运行php只会告诉它在哪里可以找到其配置文件。 The -r option tells it to run the code provided. -r选项告诉它运行提供的代码。

What your command is doing is fetching some remote PHP code and then piping it to another PHP process to be executed. 您的命令正在做的是获取一些远程PHP代码,然后将其通过管道传递到另一个要执行的PHP进程。

Unless you happen to have a special configuration requirement (and have a php.ini file in the current directory) the -c option isn't needed. 除非您碰巧有特殊的配置要求(并且当前目录中有php.ini文件),否则不需要-c选项。

I don't recommend doing this, by the way. 顺便说一句,我不建议这样做。 It's an unnecessary risk to run unknown code on your machine, even it it appears to be coming from a known source. 在您的计算机上运行未知代码是不必要的风险,即使它似乎来自已知来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM