整理一下命令行下的PHP參數(shù)使用。輸入php -h ,查看幫助,可以調出PHP官方提供的參數(shù)說明。
# php -h
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -S <addr>:<port> [-t docroot] [router]
php [options] -- [args...]
php [options] -a
-a Run as interactive shell
-c <path>|<file> Look for php.ini file in this directory
-n No configuration (ini) files will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse and execute <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-B <begin_code> Run PHP <begin_code> before processing input lines
-R <code> Run PHP <code> for every input line
-F <file> Parse and execute <file> for every input line
-E <end_code> Run PHP <end_code> after processing all input lines
-H Hide any passed arguments from external tools.
-S <addr>:<port> Run with built-in web server.
-t <docroot> Specify document root <docroot> for built-in web server.
-s Output HTML syntax highlighted source.
-v Version number
-w Output source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
--ini Show configuration file names
--rf <name> Show information about function <name>.
--rc <name> Show information about class <name>.
--re <name> Show information about extension <name>.
--rz <name> Show information about Zend extension <name>.
--ri <name> Show configuration for extension <name>.
下面來逐一說明參數(shù)的含義。
php -a
進入一個交互式命令模式,輸入php命令回車后立即執(zhí)行,執(zhí)行完后等待下一條命令鍵入,exit退出,多條命令可用 分號 間隔,方向鍵上和下可以調出歷史命令,平時需要臨時調試一個 正則表達式 或當個計算器非常實用。
# php -a
Interactive shell
php > echo "hello world";
hello world
php > echo 100+100;
200
php > exit
php -c
指定 php.ini 配置文件所在的目錄或指定一個php配置文件,如:
php -c ./php.ini test.php
# php -c /home/htf/my_php.ini
php -n
忽略php.ini配置文件執(zhí)行
php -d
用bar代替配置文件中foo的值
php -f <file>
解析并執(zhí)行一個php腳本文件,默認執(zhí)行時以有這個參數(shù)
php -h
查看命令行下PHP參數(shù)的信息說明
php -i
查看php的信息。命令行下的phpinfo參數(shù)
# php -i|grep redis
/usr/local/etc/php/conf.d/docker-php-ext-redis.ini,
redis
Registered save handlers => files user redis rediscluster
This program is free software; you can redistribute it and/or modify
php -l <file>
檢查文件的語法信息。例如有check_syntax.php
<?php
echo hello world"
?>
# php -l check_syntax.php
Parse error: syntax error, unexpected 'world' (T_STRING), expecting ',' or ';' in check_syntax.php on line 2
Errors parsing check_syntax.php
php -m
顯示命令行環(huán)境下加載的PHP模塊
php -r <script>
執(zhí)行PHP代碼
# php -r "echo 'hello world'.PHP_EOL;"
hello world
php -s <file>
輸出代碼高亮的html格式內容。
php -v
顯示php的版本信息
php -w <file>
將源代碼中的內容去除注釋和空白行后進行展示
# cat check_syntax.php
<?php
//php say hello
echo "hello world";
//finish
?>
# php -w check_syntax.php
<?php
echo "hello world"; ?>