Usage: php [options] [-f] <file> [args...]
php [options] -r <code> [args...]
php [options] [-- args...]
-s Display colour syntax highlighted source.
-w Display source with stripped comments and whitespace.
-f <file> Parse <file>.
-v Version number
-c <path>|<file> Look for php.ini file in this directory
-a Run interactively
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-z <file> Load Zend extension <file>.
-l Syntax check only (lint)
-m Show compiled in modules
-i PHP information
-r <code> Run PHP <code> without using script tags <?..?>
-h This help
args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
# Ommiting the value part will set the given configuration directive to "1"
$ php -d max_execution_time
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(1) "1"
# Passing an empty value part will set the configuration directive to ""
php -d max_execution_time=
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(0) ""
# The configuration directive will be set to anything passed after the '=' character
$ php -d max_execution_time=20
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(2) "20"
$ php
-d max_execution_time=doesntmakesense
-r '$foo = ini_get("max_execution_time"); var_dump($foo);'
string(15) "doesntmakesense"
-e
為偵錯器等產生擴充資訊。
-z
載入 Zend 擴充功能庫。如果僅給定一個檔案名,PHP 將試圖從您系統擴充功能庫的預設路徑(在 Linux 系統下,該路徑通常由 /etc/ld.so.conf 指定)載入該擴充功能庫。如果您用一個絕對路徑指定檔案名,則系統的擴充庫預設路徑將不會被使用。如果使用相對路徑指定的檔案名,PHP 則僅試圖載入相對於目前目錄的擴充庫。
-l
此參數提供了對指定 PHP 程式碼進行語法檢查的方便的方法。如果成功,則向標準輸出寫入 No syntax errors detected in 字串,並且外殼回傳值為 0。如果失敗,則 Errors parsing 以及內部解析器錯誤訊息會一起寫入標準輸出,同時外殼回傳值將別設為 255。
此參數將無法檢查致命錯誤(如未定義函數),如果您希望偵測之名錯誤,請使用 -f 參數。
附註: 此參數不能和 -r 一同使用。
-m
使用此參數,PHP 將列印內建以及已加載的PHP 及Zend 模組:
$ php -m
[PHP Modules]
xml
tokenizer
standard
session
posix
pcre
overload
mysql
mbstring
ctype
[Zend Modules]
-i
此指令列參數會呼叫 phpinfo() 函數,並列印出結果。如果 PHP 沒有正常運作,我們建議您執行 php -i 指令來檢視在資訊表格之前或對應的地方是否有任何錯誤訊息輸出。請注意輸出的內容為 HTML 格式,因此輸出的資訊篇幅較大。
PHP 的命令列模式能使得 PHP 腳本能完全獨立於 WEB 伺服器單獨運作。如果您使用 Unix 系統,您需要在您的 PHP 腳本的最前面加上一行特殊的程式碼,使得它能夠被執行,這樣系統就能知道用什麼樣的程式要執行該腳本。在 Windows 平台下您可以將 php.exe 和 .php 檔案的雙擊屬性相關聯,您也可以編寫一個批次檔來用 PHP 執行腳本。為 Unix 系統增加的第一行程式碼不會影響該腳本在 Windows 下的執行,因此您也可以用該方法編寫跨平台的腳本程式。以下是一個簡單的PHP 命令列程式的範例。
###### #範例23-1. 試圖以命令列方式執行的PHP 腳本(script.php)# ######!/usr/bin/phpThis is a command line PHP script with one option. Usage: be< <can<can<can<); you would like to print out. With the --help, -help, -h, or -? options, you can get this help.在上述腳本中,我們用第一行特殊的程式碼來指明該檔案應該由 PHP 來執行。我們在這裡使用 CLI 的版本,因此不會有 HTTP 頭資訊輸出。當您用 PHP 編寫命令列應用程式時,您可以使用兩個參數:$argc 和 $argv。前面一個的值是比參數個數大 1 的整數(運行的腳本本身的名稱也被當作一個參數)。第二個時包含有參數的數組,其第一個元素為腳本的名稱,下標為數字 0($argv[0])。