2016-04-08 13 views
2

私はトラブルこのLinuxコマンドを理解することが生じています:
php -r "readfile('https://getcomposer.org/installer');" | php -c php.ini理解配管:PHP -c

最初の部分php -rphp -cにパイピングされて表示されます。しかし、php.iniであると表示され、と表示されます。

phpコマンドオプションの詳細はどこで(-vと-c)を意味するのですか?コマンドの動作を知るにはどうすればよいですか? man phpから

+1

[documentation](http://php.net/manual/en/features.commandline.options.php)の何が問題なのですか? –

+1

@JoeHabadas私はPHPの初心者です。どうやって分かったの?私は "PHPオプション"、 "PHP -c"、 "PHP -v"を検索し、見つからなかった。 – Tosh

+0

'php --help'、' man php' ...あなたはインターネットを必要としません。 –

答えて

3

:対話的に実行PHP -a

OPTIONS --interactive 。これにより、直接実行される PHPコードのスニペットを入力することができます。 readlineがポートを有効にすると、行を編集することができ、 の履歴サポートも可能です。 php.netから

--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 [オプション] [-f] [ - ] [引数...] phpの[オプション] -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 

This command runs the file https://getcomposer.org/installer using php.ini in the current directory as the config file. The same can be achieved with

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

ありがとうございます。あなたはコマンドが何をしていると思いますか? – Tosh

2

Running php-cオプションは、単に設定ファイルをどこに見つけるか指示します。 -rオプションは、提供されたコードを実行するように指示します。

あなたのコマンドが行っていることは、リモートのいくつかのPHPコードを取得し、それを別のPHPプロセスにパイプして実行することです。

特別な設定が必要な場合(および現在のディレクトリにphp.iniファイルがある場合)、-cオプションは必要ありません。

ところで、これを行うことはお勧めしません。マシン上で未知のコードを実行することは、既知のソースからのものであっても、不必要なコードを実行するリスクはありません。