了解管道:PHP -c

时间:2016-04-08 03:42:27

标签: php shell

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

看来第一部分php -r正在引导php -c。但似乎php.ini正在读取

我在哪里可以找到有关php命令选项的更多信息,它们的意思是(-v和-c),从而找出命令在做什么?

2 个答案:

答案 0 :(得分:3)

来自man php

  

OPTIONS          - 互动         -a以交互方式运行PHP。这可以让你输入的片段                        直接执行的PHP代码。当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

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

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


  
  

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

答案 1 :(得分:2)

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

您的命令正在执行的操作是获取一些远程PHP代码,然后将其传递给另一个要执行的PHP进程。

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

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