理解管道:PHP-c


Understanding piping: PHP -c

我很难理解这个Linux命令:
php -r "readfile('https://getcomposer.org/installer');" | php -c php.ini

第一个零件php -r似乎正在管道连接到php -c。但似乎php.ini正在被读取

我在哪里可以找到更多关于php命令选项的信息,它们的意思是(-v和-c),从而了解命令的作用?

来自man php:

选项--交互式的-a以交互方式运行PHP。这允许您输入直接执行的PHP代码。当读取线路sup端口已启用,您可以编辑行,还可以历史支持。

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

来自php.net:

用法: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

-a Run interactively -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
Parse and execute . -h This help -i
PHP information -l Syntax check only (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. -S : Run with built-in web server. -t Specify document root for built-in web server. -s
Output HTML syntax highlighted source. -v Version number -w Output source with stripped comments and whitespace. -z Load Zend extension .

args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin

--ini Show configuration file names

--rf Show information about function . --rc Show information about class . --re
Show information about extension . --rz Show information about Zend extension . --ri Show configuration for extension .

Edit:

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

此命令运行文件https://getcomposer.org/installer使用当前目录中的php.ini作为配置文件。也可以做到这一点

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

使用-c选项运行php只需"告诉"它在哪里可以找到配置文件。-r选项告诉它运行所提供的代码。

您的命令所做的是获取一些远程PHP代码,然后将其管道传输到另一个要执行的PHP进程。

除非您碰巧有特殊的配置要求(并且在当前目录中有一个php.ini文件),否则不需要-c选项。

顺便说一句,我不建议这样做。在机器上运行未知代码是不必要的风险,即使它看起来来自已知来源。